Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming 1. Task: Suppose you are writing a game-playing program that in

ID: 3667550 • Letter: J

Question

Java Programming

1. Task: Suppose you are writing a game-playing program that involves 2-digit numbers, each number being composed of 2 different digits. Test if whether numbers entered in a sequence are accepted to be used in this game. Test for errors in input (including type)

SAMPLE OUTPUT:

Enter a 2-digit number. The digits should be different. Zero to stop: rt

Not an integer, try again: f

Not an integer, try again: 34.5

Not an integer, try again: -4

NOT good for your game!

Enter a 2-digit number. The digits should be different. Zero to stop: rds

Not an integer, try again: 99

NOT good for your game!

Enter a 2-digit number. The digits should be different. Zero to stop: 23

Good for your game! Play!

Enter a 2-digit number. The digits should be different. Zero to stop: 11

NOT good for your game!

Enter a 2-digit number. The digits should be different. Zero to stop: kjhgfgfd

Not an integer, try again: 8

NOT good for your game!

Enter a 2-digit number. The digits should be different. Zero to stop: 0

Explanation / Answer

public static void main(String[] args) { int num = 1; Scanner input = new Scanner(System.in); do { System.out.println("Enter a 2-digit number. The digits should be different. zero to stop"); if (!input.hasNextInt()) { System.out.println("Not an integer,try again " + num); } else { num = input.nextInt(); if (num < 10 || num >= 99) { System.out.println("NOT good for your game! " + num); } else { System.out.println("Good for your game! Play! " + num); } } } while(num != 0); input.close(); System.out.println("game stop"); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote