How to continue loop based on user input in java program - java

I have a lottery program that will run bets and randomly generate numbers. When the user reaches $5000 in total wins, that user will have an option to cash out $5000 and use the remaining balance to continue the loop. The user will also be able to end the loop if choosing to not cash out. How do I continue a loop based on user input? If the user writes yes, the loop will continue, but I am not sure how to do that. Can someone please help? If the loop is supposed to continue, $5000 removed from the user's total win because of cashout, the remaining balance will be used to play.
I have tried putting the if statement for user input in multiple places in the main loop, but the user budget keeps increasing, it does not subtract $5000.
java.util.Scanner
while (budget > 0) {
lottery = (int) (Math.random() * 100);
guess = (int) (Math.random() * 100);
budget -= 1; // budget = budget-1;
// Get digits from lottery
int lotteryDigit1 = lottery / 10;
int lotteryDigit2 = lottery % 10;
// Get digits from guess
int guessDigit1 = guess / 10;
int guessDigit2 = guess % 10;
System.out.println("The lottery number is " + lottery);
System.out.println("The computer picked number is " + guess);
// Check the guess
if (guess == lottery) {
System.out.println("Exact match: you win $10,000");
totalWin += 1000;
} else if (guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) {
System.out.println("Match all digits: you win $3,000");
totalWin += 300;
} else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || guessDigit2 == lotteryDigit1
|| guessDigit2 == lotteryDigit2) {
System.out.println("Match one digit: you win $1,000");
totalWin += 100;
} else
System.out.println("Sorry, no match");
budget += totalWin;
totalWin=0;
if (budget > initBudget)
if ((budget-initBudget) >= 5000) {
System.out.println("You have reached the goal of 5000, we can go home!");
System.out.println("Enter 1 if you would like to cash out and use remaining balance to play and 0 if you would like to stop");
int decison = input.nextInt();
if (decison==1){budget=budget-5000;
System.out.println("Budget After play " + budget);
continue;
}break;
}
System.out.println("Budget After play " + budget);
}
So in my code, I have the loop
System.out.println("Enter 1 if you would like to cash out and use remaining balance to play and 0 if you would like to stop");
int decison = input.nextInt();
if (decison==1){budget=budget-5000;
System.out.println("Budget After play " + budget);
continue;
}break;
}
This loop should receive user input and then subtract 5000 from the total win and use the remaining budget to continue play.. but it is only increasing. Don't understand why it is increasing if I have -5000.
(if possible, please help me change the answer to a yes/no rather than input 1)

I assumed you are using java.util.Scanner. Here is the answer;
System.out.println("Enter yes if you would like to cash out and use remaining balance to play and no if you " +
"would like to stop");
String decison = input.nextLine();
if ("yes".equals(decison))
{
budget = budget - 5000;
System.out.println("Budget After play " + budget);
continue;
}
break; // break the statement.

Erçin Akçay explained how to change the input from an int to a String.
I took a look at your code and made a runnable main method using it, and it works as you would expect. Perhaps the fact that it needs to be 5k from the intial budget is confusing?
if ((budget - initBudget) >= 5000)
Here is the entire class I used to check your code if it is helpful:
import java.util.Scanner;
public class Test {
private static int budget;
private static int lottery;
private static int guess;
private static int totalWin;
private static int initBudget = 4500;
public static void main(String[] args) throws InterruptedException {
Scanner input = new Scanner(System.in);
budget = initBudget;
while (budget > 0) {
lottery = (int) (Math.random() * 100);
guess = (int) (Math.random() * 100);
budget -= 1; // budget = budget-1;
// Get digits from lottery
int lotteryDigit1 = lottery / 10;
int lotteryDigit2 = lottery % 10;
// Get digits from guess
int guessDigit1 = guess / 10;
int guessDigit2 = guess % 10;
System.out.println("The lottery number is " + lottery);
System.out.println("The computer picked number is " + guess);
// Check the guess
if (guess == lottery) {
System.out.println("Exact match: you win $10,000");
totalWin += 1000;
} else if (guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) {
System.out.println("Match all digits: you win $3,000");
totalWin += 300;
} else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || guessDigit2 == lotteryDigit1
|| guessDigit2 == lotteryDigit2) {
System.out.println("Match one digit: you win $1,000");
totalWin += 100;
} else {
System.out.println("Sorry, no match");
}
budget += totalWin;
totalWin = 0;
if (budget > initBudget) {
if ((budget - initBudget) >= 5000) {
System.out.println("You have reached the goal of 5000, we can go home!");
System.out.println(
"Enter 1 if you would like to cash out and use remaining balance to play and 0 if you "
+ "would like to stop");
int decison = input.nextInt();
if (decison == 1) {
budget = budget - 5000;
System.out.println("Budget After play " + budget);
continue;
}
break;
}
}
System.out.println("Budget After play " + budget);
}
}
}

You can change your code like this:
System.out.println("Enter yes if you would like to cash out and use remaining balance to play and no if you would like to stop");
String decision = input.next();
if ("Yes".equalsIgnoreCase(decision)) { // Cashing Out
budget = budget - 5000;
System.out.println("Budget After play " + budget);
continue;
}
break; // breaking the loop (if user enters anything other than yes)
Here I have used String (to store User's response as a word). If he enters Yes, yes or YES (ignoring the case, it will be considered that user wants to cash out) the loop will not break.

Related

Do-While loop doesn't terminate when condition is false

This is a game where you can take biscuits from barrels, either from barrel1, barrel2, or both. The last player to take the last biscuits wins the game. I implemented the game in a do-while loop so that it loops every turn. However, once the number of biscuits in both barrels = 0, the loop doesn't terminate and keeps on taking scanner input.
N.B. This is coursework for university, so please do not tell me exactly what to do or give me exact code, just suggestions or why my code is not working.
import java.util.Scanner;
public class LastBiscuit {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int barrel1 = 6;
int barrel2 = 8;
// Simple turn counter. incremented every loop. if even, player 2 turn
int turnCounter = 0;
do {
turnCounter++;
int howMany = 20;
String turnAction;
// prints out biscuits left in each barrel
String output1 = String.format("Biscuits Left - Barrel 1: %d",barrel1);
String output2 = String.format("Biscuits Left - Barrel 2: %d",barrel2);
System.out.println(output1);
System.out.println(output2);
// Check turn counters value. If even, it is player 2 turn, else player 1 turn.
if (turnCounter % 2 == 0) {
System.out.println("Player Turn: 2");
}
else {
System.out.println("Player Turn: 1");
}
// Player picks what action to take in their turn. Stored in turnAction. Only allows correct input
System.out.print("Choose a barrel: barrel1 (one), barrel2 (two), or both (both), or skip turn (skip)?");
do {
turnAction = in.next();
} while (!turnAction.equalsIgnoreCase("one") && !turnAction.equalsIgnoreCase("two") &&
!turnAction.equalsIgnoreCase("both") && !turnAction.equalsIgnoreCase("skip"));
// Player picks how many biscuits to take, if at all. If biscuits taken larger than biscuits remaining,
// they have to re-enter integer
if (!(turnAction.equalsIgnoreCase("skip"))) {
System.out.print(" How many biscuits are you taking?");
while(!in.hasNextInt()) {
System.out.println("Try again");
in.next();
}
howMany = in.nextInt();
while (barrel1 - howMany < 0 || barrel2 - howMany < 0 || howMany <= 0) {
howMany = in.nextInt();
}
}
// Takes biscuits from barrels chosen
if (turnAction.equalsIgnoreCase("one")) {
barrel1 -= howMany;
}
if (turnAction.equalsIgnoreCase("two")) {
barrel2 -= howMany;
}
if (turnAction.equalsIgnoreCase("both")) {
barrel1 -= howMany;
barrel2 -= howMany;
}
// do nothing on skip
} while (barrel1 > 0 || barrel2 > 0);
//bug? doesnt print? outside of do-while loop
// doesnt exit loop?
System.out.println("YOYYYOOYOY");
if (turnCounter % 2 == 0) {
System.out.println("Player 2 Wins! ");
}
else {
System.out.println("Player 1 Wins! ");
}
}
}
You have an infinite while loop running at:
while (barrel1 - howMany < 0 || barrel2 - howMany < 0 || howMany <= 0) {
howMany = in.nextInt();
}
This only happens when you require more biscuits than a barrel contains or you request a negative number of biscuits. When it does you will be forever in this while loop.
Place a breakpoint at howMany = in.nextInt(); as already suggested and you will see it happening.

Guessing game with minimum guesses used not working in Java

I'm creating a guessing game in Java using NetBeans. The guessing game allows the user to guess a number between 1 and 10. Each round they have 5 chances to guess the number. There are three rounds in the game. After the user finishes the game, stats are outputted with the minimum # of guess and maximum # of guesses.
The minimum guesses isn't working and it always outputs 1. Right now, I have the program set up so that it keeps track of how many times the user guesses per round. After each round, it compares this value to the min value and max value. The minGuess is set as 5 since it isn't possible to guess more than 5 times. The maxGuess is set as 1 since they will always guess one time or more than one time.
static void numberGuess(int guess, int randNum) { //creating a method to check if the user has guessed the correct number or if the guess should be higher or lower
if (guess < 0 | guess > 10) {
System.out.println("Please enter a valid number between 1 and 10.");
}
else if (guess == randNum) {
System.out.println("You guessed the number correctly");
}
else if (guess < randNum) {
System.out.println("Guess is too low");
}
else if (guess > randNum) {
System.out.println("Guess is too high");
}
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
/*Rational: This program allows a user to guess a number between 1 and 10 five times per round. There are three rounds in one game.
The program then outputs the stats for the game.
*/
//declaration
int userGuess; //creates a spot in memory for these variables
int numOfGuess = 0;
int invalidGuess = 0;
int minGuess = 5;
int maxGuess = 1;
int average;
Scanner Input = new Scanner (System.in); //creates an object in the scanner clas
//execution
System.out.println("Welcome to Super Guessing Game! Guess a random number between 1 and 10. There are three rounds with one guess each.");
loopOne: //labels the loop as loopTwo
for (int x = 1; x <= 3; x= x + 1 ) { //runs the loop for three rounds
System.out.println(" ");
System.out.println("Round " + x);
System.out.println("To exit the game at any point, enter a negative 1");
System.out.println(" ");
int randNum;
randNum = 1 + (int)(Math.random() * ((10 - 1) + 1)); //generates the random number
loopTwo: //labels the loop as loopTwo
for (int y = 1; y <= 5; y= y + 1) { //runs the loop five times (five guesses per round)
numOfGuess = numOfGuess + 1; //counts number of guesses user has made
System.out.println("Guess " + y + " out of 5");
System.out.println("Please guess a number between 1 and 10: ");
userGuess = Input.nextInt();
if (userGuess == -1){ //sentinel to let the user quit at any time
System.out.println("Thank you for playing");
break loopOne; //breaks out of the loops if the user wants to stop playing
}
numberGuess(userGuess, randNum); //calls the numberGuess method
if (y < minGuess) //compares to see if the minimum number of guesses is less that the number of guesses the user has made this round
minGuess = y;
if (y > maxGuess) //compares to see if the maximum number of guesses is greater than the number of guesses that the user has made this round
maxGuess = y;
if (userGuess <1 | userGuess > 10) { //keeps track of invalid guesses
invalidGuess = invalidGuess + 1;
}
if (userGuess == randNum) { //exits the round if the user guesses correctly
break;
}
}
}
average = numOfGuess / 3; //calculates the average number of guesses
System.out.println("Thanks for playing!"); //outputs the following
System.out.println("");
System.out.println("Number of Guesses Made: " + numOfGuess);
System.out.println("Average Number of Guesses: " + average);
System.out.println("Number of Invalid Guesses: " + invalidGuess);
System.out.println("Minimum Guesses Used: " + minGuess);
System.out.println("Maximum Guesses Used: " + maxGuess);
}
}
y starts at one, and is never less than one, thus minGuess is always one.
for (int y = 1; y <= 5; y= y + 1) {
...
if (y < minGuess)
minGuess = y;
...
}
Consider only updating minGuess and maxGuess upon a successful guess.
Your if statement is at the wrong place.
Your asking every time. also if the user isnt guessing the right number.
so just put it in ur numberguess method:
else if (guess == randNum) {
System.out.println("You guessed the number correctly");
if (y < minGuess) //compares to see if the minimum number of guesses is less that the number of guesses the user has made this round
minGuess = y;
if (y > maxGuess) //compares to see if the maximum number of guesses is greater than the number of guesses that the user has made this round
maxGuess = y;
}

lottery program without arrays with java

hello guys i am really stuck, its about a lottery program that randomly generate a four-digit number and prompt the user to enter a four-digit number without using array and following this rules
-if the user input match the lottery number in exact order the award is $10000
-if the user input match the four-digit in different order the award is $5000
-if the user input match the three-digit number in different order the award is $2000
-if any 1 or 2-digit in the user input match the lottery the award is $500
i did it for a 3-digit number but i don't know how to do it for a four-digit number without arrays.this is what i have done :
import java.util.Scanner;
public class Programming {
public static void main(String[] args) {
// Generate a lottery
int lottery = (int) (Math.random() * 1000);
// Prompt the user to enter a guess
Scanner input = new Scanner(System.in);
System.out.print("Enter your lottery pick (three digits): ");
int guess = input.nextInt();
// Get digits from lottery
int lotteryDigit1 = lottery / 100;
int lotteryDigit2 = (lottery % 100) / 10;
int lotteryDigit3 = lottery % 10;
// Get digits from guess
int guessDigit1 = guess / 100;
int guessDigit2 = (guess % 100) / 10;
int guessDigit3 = guess % 10;
System.out.println("The lottery number is " + lotteryDigit1
+ lotteryDigit2 + lotteryDigit3);
// Check the guess
if (guess == lottery) {
System.out.println("Exact match: you win $10,000");
} else if ((guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit1 && guessDigit3 == lotteryDigit3)
|| (guessDigit1 == lotteryDigit2
&& guessDigit1 == lotteryDigit3 && guessDigit3 == lotteryDigit1)
|| (guessDigit1 == lotteryDigit3
&& guessDigit2 == lotteryDigit1 && guessDigit3 == lotteryDigit2)
|| (guessDigit1 == lotteryDigit3
&& guessDigit2 == lotteryDigit2 && guessDigit3 == lotteryDigit1)
|| (guessDigit1 == lotteryDigit1
&& guessDigit2 == lotteryDigit3 && guessDigit3 == lotteryDigit2)) {
System.out.println("Match all digits: you win $5,000");
} else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2
|| guessDigit1 == lotteryDigit3 || guessDigit2 == lotteryDigit1
|| guessDigit2 == lotteryDigit2 || guessDigit2 == lotteryDigit3
|| guessDigit3 == lotteryDigit1 || guessDigit3 == lotteryDigit2
|| guessDigit3 == lotteryDigit3) {
System.out.println("Match one digit: you win $1,000");
} else {
System.out.println("Sorry, no match");
}
}
}
thank you for your help
Another Edit
Sorry for taking a while to get back to you. Been a busy couple days. As requested, here is the complete program. Note that this isn't entirely your original program. I removed a couple things and added a few more in. Perhaps most importantly, I changed the function that I gave you previously. I originally answered your question to try to only give you the four digit match but if I am writing out the whole thing it makes more sense to generalize a bit. Because your lottery awards are based on the number of matching digits, it makes a lot of sense to make a function that counts how many digits match. This simplifies your if-else code a whole lot.
import java.util.Scanner;
public class Programming {
/*
* get the number of matching digits between the guess and the
* answer, ignoring repeated matches
*/
public static int numberDigitsMatch(String guess, String answer) {
int numberMatch = 0;
int currentIndex = 0;
int matchingIndex;
while (currentIndex < guess.length()) {
// check if the current digit of the guess is in the answer
matchingIndex = answer.indexOf(guess.charAt(currentIndex));
if (matchingIndex < 0) {
currentIndex++;
}
else {
currentIndex++;
numberMatch++;
// remove the no longer relevant character from the answer
answer = answer.substring(0, matchingIndex) +
answer.substring(matchingIndex + 1);
}
}
return numberMatch;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// generate the winning number
int lotteryNumber = (int) (Math.random() * 10000);
String lotteryString = "" + lotteryNumber;
System.out.println("The lottery number is " + lotteryString);
// Prompt the user to enter a guess
System.out.print("Enter your lottery pick (four digits): ");
// get the user's guess
int guessNumber = in.nextInt();
String guessString = "" + guessNumber;
// NOTE: these guessDigit numbers are not necessary. I am leaving
// them here so you can see how to pick out individual digits
int guessDigit1 = guessNumber % 10;
int guessDigit2 = (guessNumber / 10) % 10;
int guessDigit3 = (guessNumber / 100) % 10;
int guessDigit4 = (guessNumber / 1000) % 10;
int lotteryDigit1 = lotteryNumber % 10;
int lotteryDigit2 = (lotteryNumber / 10) % 10;
int lotteryDigit3 = (lotteryNumber / 100) % 10;
int lotteryDigit4 = (lotteryNumber / 1000) % 10;
System.out.println("The lottery number is " + lotteryString);
int numMatchingDigits = numberDigitsMatch(guessString, lotteryString);
if (guessNumber == lotteryNumber) {
System.out.println("Exact match: you win $10,000");
}
else if (4 == numMatchingDigits) {
System.out.println("Match all digits: you win $5,000");
}
else if (3 == numMatchingDigits) {
System.out.println("Match three digits: you win $2,000");
}
else if (2 == numMatchingDigits) {
System.out.println("Match two digits: you win $500");
}
else if (1 == numMatchingDigits) {
System.out.println("Match two digit: you win $500");
}
else {
System.out.println("Sorry, no match");
}
}
}
Edit
Looks like I did not understand correctly. I believe there are multiple ways to get a given digit of a number but I think this is the easiest to think about. You divide by 1000 to shift the thousands digit into the 1's place then use the modulus operator to get rid of anything that isn't in the 1's place. This leaves you with nothing but the fourth digit of the number.
public static int getFourthDigit(int num) {
return (num / 1000) % 10;
}
Original
If I understand correctly, your difficulty is with matching different ordered four digit numbers. The most obvious way to do this is to just check all possible orderings of the four digits; there are only 15 where they are not exactly equal. However, typing out 15 conditions is prone to errors and just plain boring. It would be twice as boring and tedious if you instead needed to do this with five digits.
Here is a function that avoids this by using String instead of int. It repeatedly checks the first character of the guess and checks if the character is in the answer. It then removes that matching character from the answer to avoid a case like 1111 and 1112, where every character in the guess is also in the answer but they do not match.
public static boolean digitsMatch(String guess, String answer) {
int matchingIndex;
while (guess.length() > 0) {
// check if the first digit of the guess is in the answer
matchingIndex = answer.indexOf(guess.charAt(0));
// if not, there cannot possibly be four matches
if (matchingIndex < 0) {
return false;
}
// look at the rest of the guess
guess = guess.substring(1);
// and remove the no longer relevant character from the answer
answer = answer.substring(0, matchingIndex) +
answer.substring(matchingIndex + 1);
}
return true;
}

Credit Card Number validity with Luhn's Algorithm (Java)

I'm working on a school assignment that checks whether a credit card number that is entered is valid or not, using Luhn's Algorithm.
In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. Credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388 5760 1840 2626):
Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
Now add all single-digit numbers from Step 1: 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37
Add all digits in the odd places from right to left in the card number: 6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
Sum the results from Step 2 and Step 3: 37 + 38 = 75
If the result from Step 4 is divisible by 10 the card number is valid; otherwise, it is invalid. For example, the number 4388 5760 1840 2626 is invalid, but the number 4388 5760 1841 0707 is valid.
I need to write this program using the methods in the code I have written:
public class CreditCardValidation {
public static void main(String[] args, long input) {
Scanner numberinput = new Scanner(System.in);
System.out.println("Enter a credit card number as a long integer: ");
long cardnumber = numberinput.nextLong();
if (isValid(input) == true) {
System.out.println(numberinput + " is valid.");
} else {
System.out.println(numberinput + " is invalid.");
}
}
public static boolean isValid(long number){
int total = sumOfDoubleEvenPlace + sumOfOddPlace;
return (total % 10 == 0) && (prefixMatched(number, 1) == true) &&
(getSize(number)>=13) && (getSize(number)<=16);
}
public static int sumOfDoubleEvenPlace(long number) {
int doubledevensum = 0;
long place = 0;
while (number > 0) {
place = number % 100;
doubledevensum += getDigit((int) (place / 10) * 2);
number = number / 100;
}
return doubledevensum;
}
public static int sumOfOddPlace(long number) {
int oddsum = 0;
while (number <= 9) {
oddsum += (int)(number % 10);
number = number % 100;
}
return oddsum;
}
public static int getDigit(int number) {
if (number <= 9) {
return number;
} else {
int firstDigit = number % 10;
int secondDigit = (int)(number / 10);
return firstDigit + secondDigit;
}
}
public static boolean prefixMatched(long number, int d) {
if ((getPrefix(number, d) == 4)
|| (getPrefix(number, d) == 5)
|| (getPrefix(number, d) == 3)) {
if (getPrefix(number, d) == 3) {
System.out.println("\nVisa Card ");
} else if (getPrefix(number, d) == 5) {
System.out.println("\nMaster Card ");
} else if (getPrefix(number, d) == 3) {
System.out.println("\nAmerican Express Card ");
}
return true;
} else {
return false;
}
}
public static int getSize(long d) {
int count = 0;
while (d > 0) {
d = d / 10;
count++;
}
return count;
}
public static long getPrefix(long number, int k) {
if (getSize(number) < k) {
return number;
} else {
int size = (int)getSize(number);
for (int i = 0; i < (size - k); i++) {
number = number / 10;
}
return number;
}
}
}
I just started learning how to program two months ago so I am fairly new to this. The program doesn't compile and I don't know why and what I have to do to fix this. I know there are similar topics already posted regarding this and I have been using this post to help guide me a bit. Can someone help point a student in the right direction and let me know what I'm doing wrong?
Your program isn't compiling because this line:
int total = sumOfDoubleEvenPlace + sumOfOddPlace;
since sumOfDoubleEvenPlace and sumOfOddPlace are functions, you must use them as such:
int total = sumOfDoubleEvenPlace(number) + sumOfOddPlace(number);
In the function isValid you are trying to add two variables which do not exist. However you have defined them as functions and to use them as functions you must call them as functions using
int total = sumOfDoubleEvenPlace(number) + sumOfOddPlace(number);

Java Number Sequence Generator Not Working

Having trouble with this code that am I writing. The purpose of the code is to formulate modifiers for a number sequence and then give the first 10 numbers in that sequence. However, something appears to be wrong with my loop mechanism because it is printing out an infinite amount of values when it should only be doing 10. I plan on including the division and power functions to the code, but ran into this problem.
import java.util.Scanner;
public class PatternCreator {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out
.println("Please enter the starting value of the number sequence.");
double sequence = s.nextInt();
System.out
.println("Please enter the addition/subtraction modifier; e.g. 2,-2.");
double addsub = s.nextInt();
System.out
.println("Please enter the multiplication modifier; 0 for none.");
double mult = s.nextInt();
System.out.println("Please enter the division modifier; 0 for none.");
double divi = s.nextInt();
System.out
.println("Please enter the exponential modifier; 0 for none.");
double power = s.nextInt();
double addonly = sequence + addsub;
while (mult == 0 && divi == 0 && power == 0) {
for (int count1 = 1; count1 <= 10; count1++) {
if (count1 == 1) {
System.out.print(sequence + " ");
} else {
System.out.print(addonly + " ");
addonly = addonly + addsub;
}
}
}
double multadd = sequence + addsub * mult;
while (mult != 0 && divi == 0 && power == 0) {
for (int count2 = 1; count2 <= 10; count2++) {
if (count2 == 1) {
System.out.print(sequence + " ");
} else {
System.out.print(multadd + " ");
multadd += multadd;
}
}
}
}
}
Sounds like mult, divi, and power are all 0, and you never change them-- therefore you're executing your while loop (and therefore your for loop) an infinite number of times.
Why do you have that while loop there at all?
You never, ever, change the values of multi, divi or power. How do you expect the while to end if those values never change?

Categories

Resources