Java Programming 1. Task: Suppose you are writing a game-playing program that in
ID: 3667301 • 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
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) 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: 0Explanation / Answer
Program in java is given below:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner ;
class gameClass
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner input = new Scanner(System.in);
int x;
boolean a = true;
while(a)
{
System.out.println("Enter a 2-digit number. The digits should be different. Zero to stop : ");
while(!input.hasNextInt())
{
System.out.println("Not an integer, try again:");
continue;
}
x = input.nextInt();
if(x == 0)
break;
if (x >= 10 && x <= 99)
{
if(x %11 == 0)
{
System.out.println("NOT good for your game!");
continue;
}
System.out.println("Good for your game! Play!");
continue;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.