my 2nd if statement is being ignored dont know why - java

Hello guys i am basically creating a program that takes about 5 inputs from users and stores them in an array called course....every time user enter 1 course i want to ask the user if he wants to continue.. if he type yes the program continues or else it shows the values in array(course)......
i am facing issues :-
1.i dont wanna ask user to continue if he is already entering the last value which is 5th one.
2.my 2nd loop is basically being ignored i dont know why if it works every thing would've been ok.
3.if the user enters last value and press yes according to my program it is still not printing the values in my course(array).
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ArrayExample;
import java.util.Scanner;
/**
*
* #author jodh_
*/
public class ArrayExample {
public static void main(String args[]) {
String[] course = new String[5];
for (int i = 0; i < 5; i++) {
System.out.println("Please enter course name " + (i + 1) + ": ");
Scanner gettingname = new Scanner(System.in);
String coursenames = gettingname.nextLine();
course[i] = coursenames;
if (i < 4) {
for(int j =0; j<4; j++){
System.out.println("");
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
Scanner gettingYesOrNo = new Scanner(System.in);
String input = gettingYesOrNo.nextLine();
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes")) {
System.out.println("");
break;
} else if (input.isEmpty()) {
System.out.println("Input cannot be empty!! Please try again");
} else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N")) {
System.out.println("Your select courses are as follows");
}
for (int x = 0; x < i + 1; x++) {
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
System.exit(0);
}
}
}
}
}

This will work fine if you change the break to continue.Try my code.
String[] course = new String[5];
for (int i = 0 ; i < 5 ; i++){
System.out.println("Please enter course name " + (i + 1) + ": ");
Scanner gettingname = new Scanner(System.in);
String coursenames = gettingname.nextLine();
course[i] = coursenames;
if (i < 4){
System.out.println("");
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
Scanner gettingYesOrNo = new Scanner(System.in);
input = gettingYesOrNo.nextLine();
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes")) {
System.out.println("");
continue;
} else if (input.isEmpty()) {
System.out.println("Input cannot be empty!! Please try again");
} else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N")) {
System.out.println("Your select courses are as follows");
}
}
for (int x = 0; x < i + 1; x++) {
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
}
}
Here is the output
Please enter course name 1:
androiid
Would you like to continue? ((y)Yes / (n)No)
y
Please enter course name 2:
dsfnfv
Would you like to continue? ((y)Yes / (n)No)
y
Please enter course name 3:
sfgngff
Would you like to continue? ((y)Yes / (n)No)
y
Please enter course name 4:
grgngr
Would you like to continue? ((y)Yes / (n)No)
y
Please enter course name 5:
fgmt
1: androiid
2: dsfnfv
3: sfgngff
4: grgngr
5: fgmt
Process finished with exit code 0

I've made quite a few changes in your code like removing some unnecessary loops but its working now
public static void main(String args[]) {
String[] course = new String[5];
Scanner gettingname = new Scanner(System.in);
int i=0;
for (; i < 5; i++) {
System.out.println("Please enter course name " + (i + 1) + ": ");
course[i] =gettingname.nextLine();
System.out.println("");
if(i==4) break;
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
Scanner gettingYesOrNo = new Scanner(System.in);
String input = gettingYesOrNo.nextLine();
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes")) {
System.out.println("");
continue;
}
else if (input.isEmpty()) {
System.out.println("Input cannot be empty!! Please try again");
}
else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N")) {
break;
}
}
System.out.println("Your select courses are as follows");
for (int x = 0; x < i+1 ; x++) {
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
}
}

This is why code formatting is so very important! Spacing the nested if/else if/for statements allows you to follow the logic of your program much quicker and easier.
Here is a formatted version of your code:
import java.util.Scanner;
/** * * #author jodh_ */
public class ArrayExample
{
public static void main(String args[])
{
String[] course = new String[5];
for (int i = 0; i < 5; i++)
{
System.out.println("Please enter course name " + (i + 1) + ": ");
Scanner gettingname = new Scanner(System.in);
String coursenames = gettingname.nextLine();
course[i] = coursenames;
if (i < 4)
{
for(int j =0; j<4; j++)
{
System.out.println("");
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
Scanner gettingYesOrNo = new Scanner(System.in);
String input = gettingYesOrNo.nextLine();
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes"))
{
System.out.println("");
break;
}
else if (input.isEmpty())
{
System.out.println("Input cannot be empty!! Please try again");
}
else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N"))
{
System.out.println("Your select courses are as follows");
}
for (int x = 0; x < i + 1; x++)
{
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
System.exit(0);
}
}
}
}
}
In this formatted code we can easily see where each piece of code is being executed.
If you take a look at the part that checks for "yes" you will see that if the conditions are met it breaks out of the inner for loop. This means that all code underneath this break within the inner loop is not executed if the user gives an answer of "yes".
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes"))
{
System.out.println("");
break;
}
Your print statement is inside this inner for loop, which in fact means that it will only execute if the conditions of the "yes" if statement are not met. If you were to input the text "cat" in the "would you like to continue?" prompt it would skip all the if/else if statements since none of them are being met, execute the print loop, output the courses, and System.exit(0); terminate the program.
It appears that the intended purpose is to output the courses if the user inputs "no". So lets see if we can move the print loop inside the "no" if.
else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N"))
{
System.out.println("Your select courses are as follows");
for (int x = 0; x < i + 1; x++)
{
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
System.exit(0);
}
This will output the courses only if the user inputs "no". And then it will termanate the program. Perfect!
So lets talk about this empty input condition:
else if (input.isEmpty())
{
System.out.println("Input cannot be empty!! Please try again");
}
Unless you need to specifically check that the input is empty you probably want to replace this with just an else statement. Lets see what that would look like.
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes"))
{
System.out.println("");
break;
}
else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N"))
{
System.out.println("Your select courses are as follows");
for (int x = 0; x < i + 1; x++)
{
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
System.exit(0);
}
else
{
System.out.println("Invalid input!! Please try again.");
j--;
}
You need to decrement j because at the end of the for loop it will increment forward to the next course. Since the user input was invalid we want to keep the course iterator right where it is and continue to ask the user if they woud like to continue until a valid selection has been made.
We're almost there!
Now that we have sorted the input conditions, what happens when the user reaches the 5th course?
Right now we only have the courses print if the user answers "no". So at the end of the course loop we need to print the full course string array. The final product looks like so:
import java.util.Scanner;
/** * * #author jodh_ */
public class ArrayExample
{
public static void main(String args[])
{
String[] course = new String[5];
for (int i = 0; i < 5; i++)
{
System.out.println("Please enter course name " + (i + 1) + ": ");
Scanner gettingname = new Scanner(System.in);
String coursenames = gettingname.nextLine();
course[i] = coursenames;
if (i < 4)
{
for(int j =0; j<4; j++)
{
System.out.println("");
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
Scanner gettingYesOrNo = new Scanner(System.in);
String input = gettingYesOrNo.nextLine();
if (input.equals("yes") || input.equals("y") || input.equals("Y") || input.equals("YES") || input.equals("Yes"))
{
System.out.println("");
break;
}
else if (input.equals("no") || input.equals("No") || input.equals("NO") || input.equals("n") || input.equals("N"))
{
System.out.println("Your select courses are as follows");
for (int x = 0; x < i + 1; x++)
{
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
System.exit(0);
}
else
{
System.out.println("Invalid input!! Please try again");
j--;
}
}
}
}
System.out.println("Your select courses are as follows");
for (int x = 0; x < 5; x++)
{
System.out.println("");
System.out.println((x + 1) + ": " + course[x]);
}
}
}
Note: There are more optimal ways to get to the same result but I tried to keep the code as close to the original logic as possible.

Here's some code I wrote that might fix your program. You'll have to implement the rest but it should be easy enough.
import java.util.Scanner;
public class ArrayExample {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] course = new String[5];
String yesOrNo;
int index = 0;
do{
System.out.println("Please enter course name " + (index + 1) + ": ");
course[index] = input.nextLine();
if(index < 4) {
System.out.println("Would you like to continue? ((y)Yes / (n)No)");
yesOrNo = input.nextLine();
}
index++;
}while(yesOrNo.toLowerCase().startsWith("y) && index < 5)
//if the loop is exited then we know either the user chose not to continue or all the course names have been filled
//handle that here
}
}
The logic of what I did:
The while loop condition makes it so that you won't continue looping when all the courses are filled. And inside of the loop it checks if the index is not 4.
there's no more need for your second loop
you can print your array after the loop now.
Making two scanners is completely useless and takes up memory because you didn't even close them.
I hope this helps.

Related

How to break from a loop after finding a word

I am trying to create a Hangman and I have 2 problems.
1) The first problem is when the user finds the word, the loop does not stop.
2) I have a variable attempts which allows to know the number of attempts. Even if the user finds the letter, the number of attempts decrease.
The word to find is no
Here is a demonstration:
1) I enter the letter n
You have 5 attempts.
--
Enter your letter : n
2) I enter the letter o
The letter is good.
You have 4 attempts.
n-
Enter your letter : o
3) Normally the loop should stop.
The letter is good.
You have 3 attempts.
no
Enter your letter :
If you have an idea thank you in advance.
Scanner input = new Scanner(System.in);
char letter = 0;
String[] words = {/*"yes",*/ "no"};
String word_random = words[(int) (Math.random() * words.length)];
boolean[] word_found = new boolean[word_random.length()];
int attempts = 5;
while(attempts > 0){
System.out.println("You have " + attempts + " attempts.");
for(int i=0; i<word_random.length(); i++) {
if ( word_found[i] ) {
System.out.print(word_random.charAt(i));
}
else {
System.out.print('-');
}
}
System.out.println("");
System.out.print("Enter your letter : ");
letter = input.next().charAt(0);
for(int i=0; i<word_random.length();i++){
if(word_random.charAt(i) == letter){
System.out.println("The letter is good. ");
word_found[i] = true;
}
}
attempts--;
}
}
}
You are just missing a checking loop or method. Check the solution below.
Scanner input = new Scanner(System.in);
char letter = 0;
String[] words = {/*"yes",*/ "no"};
String word_random = words[(int) (Math.random() * words.length)];
boolean[] word_found = new boolean[word_random.length()];
int attempts = 5;
while(attempts > 0){
System.out.println("You have " + attempts + " attempts.");
for(int i=0; i<word_random.length(); i++) {
if ( word_found[i] ) {
System.out.print(word_random.charAt(i));
}
else {
System.out.print('-');
}
}
System.out.println("");
System.out.print("Enter your letter : ");
letter = input.next().charAt(0);
for(int i=0; i<word_random.length();i++){
if(word_random.charAt(i) == letter){
System.out.println("The letter is good. ");
word_found[i] = true;
}
}
boolean done = true;
for(boolean b : word_found)
done = done && b;
if(done) break;
else attempts--;
}
I will follow to your solution, not suggest a better one.
Ad 1. Add a check if the array word found contains only true after your first for cycle and if there are only true values in the array, print "you won" and set attempts to 0
Ad 2. Move attempts-- to the else case of your first for cycle OR add attempts++ in the true case of your first for cycle
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char letter = 0;
String[] words = { /* "yes", */ "no" };
String word_random = words[(int) (Math.random() * words.length)];
boolean[] word_found = new boolean[word_random.length()];
int attempts = 5;
while (attempts > 0) {
System.out.println("You have " + attempts + " attempts.");
for (int i = 0; i < word_random.length(); i++) {
if (word_found[i]) {
System.out.print(word_random.charAt(i));
} else {
System.out.print('-');
}
}
System.out.println("");
System.out.print("Enter your letter : ");
letter = input.next().charAt(0);
boolean match = false;
for (int i = 0; i < word_random.length(); i++) {
if (word_random.charAt(i) == letter) {
System.out.println("The letter is good. ");
word_found[i] = true;
match = true;
if (i == word_found.length - 1) {
System.out.println("THE END: attempts: " + attempts);
return;
}
}
}
if (!match) {
attempts--;
}
}
System.out.println("THE END");
}
I suggest you to modify the last part of your code like I did, and it should work.

Can someone explain why this code keeps looping?

i'm still quite new to java, can someone explain when i enter a value that meets the requirements (1-10) that the code keeps looping back to the initial for loop? How can i amend the code to fix the problem and allow to function properly?
public void rateEpisode(Scanner sc, String seriesName, int searchEpisodeNumber, ArrayList<TVSeries> tvSeries) {
for(int i = 0; i<tvSeries.size(); i++) {
for(int j = 0; j< tvSeries.get(i).getListOfEpisodes().size(); j++){
if((seriesName.equals(tvSeries.get(i).getTitle())) &&
(searchEpisodeNumber == tvSeries.get(i).getListOfEpisodes().get(j).getEpisodeNumber())){
System.out.println("Please enter your rating(1-10) of " + tvSeries.get(i).getTitle() + ", Episode " + tvSeries.get(i).getListOfEpisodes().get(j).getEpisodeNumber() + ". "
+ tvSeries.get(i).getListOfEpisodes().get(j).getEpisodeName() + " : ");
boolean validInput = false;
int userEpRating = -1;
do{
System.out.println("Test");
validInput = false;
if(sc.hasNextInt()){
userEpRating=sc.nextInt();
sc.nextLine();
if(userEpRating < 11 && userEpRating > 0){
validInput = true;
} else{
System.out.println("Please enter a rating between 1 and 10: ");
sc.nextLine();
}
}else{
System.out.println("Please enter an integer between 1 and 10: ");
sc.nextLine();
}
}while(!validInput);
tvSeries.get(i).getListOfEpisodes().get(j).setUserEpReview(userEpRating);
}
}
}
}
Move this line
tvSeries.get(i).getListOfEpisodes().get(j).setUserEpReview(userEpRating);
to here:
if(userEpRating < 11 && userEpRating > 0){
validInput = true;
tvSeries.get(i).getListOfEpisodes().get(j).setUserEpReview(userEpRating);
return;
}
...
and add return after it.
When you call return in a method that returns nothing (void) then the method exists immediately.

Having issues with having a program re-run

I am writing a program that will ask the user to guess a random number 6 times. The program has to ask if they want to play again and will keep a running total of the wins/losses.
How would I have the program rerun?
heres the code:
import java.util.Scanner;
import java.util.Random;
public class Project {
public static void main(String[] args) {
String input;
double guess = 0;
int number;
double wins = 0;
double losses = 0;
String repeat;
Scanner keyboard = new Scanner(System.in);
Random randomNumbers = new Random();
System.out.println("Welcome to Higher/Lower!");
System.out.println("Enter your name: ");
input = keyboard.nextLine();
while(input.equalsIgnoreCase("yes")); {
number = randomNumbers.nextInt(100) + 1;
System.out.println("I've chosen my number, " + input + "You only have 6 tries, good luck!"); }
for(int num = 1; number != guess && number <= 6; num++) {
System.out.println("Enter guess " + num + ":");
guess = keyboard.nextDouble();
if(guess < number)
System.out.println("higher.");
else if(guess > number)
System.out.println("lower.");
else
System.out.println("Congratulations!"); }
if(guess == number) {
System.out.println("You guesses my number!"); wins++; }
if(guess != number) {
System.out.println("Sorry, " + input + " my number was " + number +
"You lose!"); losses++; }
System.out.println("Do you want to play again? (Yes/No): ");
repeat = keyboard.nextLine();
if(input.equalsIgnoreCase("no")); {
System.out.println("Thanks for playing!"); }
System.out.println(wins + " wins");
System.out.println(losses + " losses");
}
}
It is skipping over asking me if i want to play again or not and i dont know what kind of loop to use
Wihtout your code, I'm assuming this is what you need.
boolean doContinue = true;
do {
//guess random number 6 times
//do you want to continue?
// yes -> doContinue = true;
// no -> doContinue = false;
} while (doContinue );
I would suggest making your loop a do-while loop like this:
do {
for (int i=0; i<6; i++){
/*
insert code for the guessing/checking/etc.
*/
}
System.out.print("Would you like to continue? [Y/n] ");
} while (scan.next().toUpperCase().charAt(0) != 'Y');

Loops and logic statements

I have this program needed for class and the way they ask me to complete it is confusing me as i am unable to output the proper answer. what is needed is a series of inputs that contain a series of 'x''s 'X''s and 'r''s which in turn outputs a sound. if the input contains a character that is not an 'x' 'X' or an 'r' it must output something along the lines of "please enter a valid input." For the most part i had everything down but i am unable to figure out a way to properly display the invalid input string.
import java.util.Scanner;
public class String2Beat { //main class
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("To play a drum song please enter a series of x's and r's.");
System.out.println("Use an Uppercase X for the base drum, ");
System.out.println("Use a Lowercase x for the snare drum, ");
System.out.println("Or use a Uppercase R for a rest:");
String drums = scan.nextLine();
for (int j = 0; j < 3; j++){
for (int i = 0; i < drums.length(); i++){
if (drums.charAt(i) != 'x' && drums.charAt(i) != 'X' && drums.charAt(i) != 'r'){
System.out.println("not a valid string input");
}
else {
if (drums.charAt(i) == 'X'){
System.out.println("Now playing a Bass Drum. " + drums.charAt(i));
playBass();
}
else if(drums.charAt(i) == 'x'){
System.out.println("Now playing a Snare Drum. " + drums.charAt(i));
playSnare();
}
else if(drums.charAt(i) == 'r'){
System.out.println("Now playing a Rest. " + drums.charAt(i));
playRest();
}
}
}
}
scan.close();
}
What you need to do is figure out if the String contains an invalid input before you play the sounds. Your program should probably look something like this:
import java.util.Scanner;
public class String2Beat { //main class
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("To play a drum song please enter a series of x's and r's.");
System.out.println("Use an Uppercase X for the base drum, ");
System.out.println("Use a Lowercase x for the snare drum, ");
System.out.println("Or use a Uppercase R for a rest:");
String drums = scan.nextLine();
boolean test = false;
for (int i = 0; i < drums.length(); i++)
{
if (drums.charAt(i) != 'X' || drums.charAt(i) != 'x' || drums.charAt(i) != 'R')
test = true;
}
if (!test)
{
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < drums.length(); i++)
{
if (drums.charAt(i) == 'X')
{
System.out.println("Now playing a Bass Drum. " + drums.charAt(i));
playBass();
}
else if(drums.charAt(i) == 'x')
{
System.out.println("Now playing a Snare Drum. " + drums.charAt(i));
playSnare();
}
else
{
System.out.println("Now playing a Rest. " + drums.charAt(i));
playRest();
}
}
}
}
}
else
{
System.out.println("not a valid string input");
}
scan.close();
}

How to exit interior loop and go back to main loop in java?

When I run this code, which is a menu with many different options. it consists of many loops. Some of which I have yet to make. But my issue arises when I have the user select "t" or the coin toss simulator. The loop begins but once the user enters the amount of coin flips say 4, it says 2.0 heads and 2.0 tails means 50.0% were heads
Type code letter for your choice: COIN TOSS SIMULATOR
Enter 0 to quit. How many tosses?
It shouldn't say type the letter for your choice: COIN TOSS SIMULATOR, enter 0 to quit. how many tosses?
Also when I enter 0 it says You have entered an invalid option. 't' is not a valid option. I want to Bring back the main menu!!!! what is going on????
public class toolBox {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
boolean properInput = false;
int usersInput;
while (!properInput) {
System.out.println("Enter seed value:");
if (myScanner.hasNextInt()) {
usersInput = myScanner.nextInt();
properInput = true;
Random randomSeed = new Random(usersInput);
String randomNumberList = "";
for (int i = 0; i < 10; i++) {
randomNumberList += randomSeed.nextInt(80) + " ";
}
} else
{
String helloWorld = myScanner.next();
System.out.println("You have not entered an integer. '" + helloWorld + "' is not an integer");
}
}
outer:
System.out.println("===== CS302 TOOL BOX =====\nT > COIN TOSS SIMULATOR\nG > GRADE ESTIMATOR\nC > COLOR CHALLENGE\nQ > QUIT");
{
Scanner anotherScanner = new Scanner(System.in);
boolean usersSelection = false;
String c;
outer:
while (!usersSelection) {
{
System.out.print("" + "Type code letter for your choice: ");
}
if (anotherScanner.hasNext("q|Q")) {
c = anotherScanner.next();
usersSelection = true;
System.out.println("" + "" + "Good-Bye");
break;
}
if (anotherScanner.hasNext("t|T")) {
{
System.out.println("" + "COIN TOSS SIMULATOR" + "");
}
System.out.println("Enter 0 to quit. How many tosses?");
Random rand = new Random();
boolean headsOrTails;
float headsCount = 0;
float tailsCount = 0;
Scanner scanMan = new Scanner(System.in);
int numero = scanMan.nextInt();
if (numero == 0) {
break outer;
}
for (int j = 0; j < numero; j++) {
headsOrTails = rand.nextBoolean();
if (headsOrTails == true) {
headsCount++;
} else {
tailsCount++;
}
}
System.out.println(headsCount + " heads and " + tailsCount + " tails means "
+ (headsCount / (headsCount + tailsCount) * 100 + "% were heads"));
}
}
if (anotherScanner.hasNext("g|G")) // if the user were to enter either case of g, the
// program will register both and initialize the
// grade estimator.
{
c = anotherScanner.next();
usersSelection = true;
}
if (anotherScanner.hasNext("c|C"))
{
c = anotherScanner.next();
usersSelection = true;
System.out.println("Welcome to the Color Challenge!");
}
else {
String zoom = anotherScanner.next();
System.out.println("You have entered an invalid option. '" + zoom + "' is not a valid option.");
}
}
}
}
Your question is not clear, but your title suggests to me you think there is an inner and outer loop.
You don't have an inner and an outer loop.
Your indentation was really messy, but when I cleaned it up and then deleted a lot of extra lines of code, the structure of the code became clear.
Notice the following:
1) You have two loops, one on top switched on !properInput, the lower one switched on !usersSelection. There is also a for loop, but it doesn't do anything related to the code flow you are asking about.
2) You have two identical labels, one outside an anonymous block of code (see my comment in the code below), and another inside the anonymous block. In this case it doesn't affect your question, but it is definitely a problem.
My guess is that your break outer line isn't working because you are breaking out of the lower while loop.
I suggest you try fragmenting your code into functions to make the structure clearer.
while (!properInput) {
}
outer:
System.out.println("===== CS302 TOOL BOX =====\nT > COIN TOSS SIMULATOR\nG > GRADE ESTIMATOR\nC > COLOR CHALLENGE\nQ > QUIT");
{ /* begin anonymous code block */
outer:
while (!usersSelection) {
if (anotherScanner.hasNext("q|Q")) {
System.out.println("" + "" + "Good-Bye");
break;
}
if (anotherScanner.hasNext("t|T")) {
System.out.println("Enter 0 to quit. How many tosses?");
if (numero == 0) {
break outer;
}
for (int j = 0; j < numero; j++) {
}
}
}
}

Categories

Resources