This program is meant to accept input 1 at a time, from the user, to formulate a FizzBuzz(Count to 100. While counting, if the number is divisible by 3, say Fizz instead. If it is divisible by 5, say Buzz instead. If it is divisible by both, say FizzBuzz.) game after complete. The first input is intended to be the first digit of the length, and second input the second digit, and third input the third digit. The next two inputs will be Fizz and the second Buzz. However, after inputting the first character in the program, it will print twice? I don't understand what is happening with my script. Here is my program (using eclipse, if you need to know)
public class Game {
public static void runFizzBuzz(int length1, int length2, int length3, int fizz, int buzz) {
String out = ""; //what to print
int foo = length1 * 100 + length2 * 10 + length3; //turns 3 digits into 3 digit num for program to read
for(int i = 0; i <= foo; i++) {
out = ""; //resets out
if(i % fizz == 0) {
out += "Fizz";
}
if(i % buzz == 0) {
out += "Buzz";
}
if(out == "") { //if neither of the above conditions pass, it will just do the number i
out += String.valueOf(i);
}
System.out.println(out); //prints solution
}
}
public static void main(String[] args)
throws java.io.IOException {
//parameters that System.in.read() should change
int param1a; //digit 1 of length
int param1b; //digit 2 of length
int param1c; //digit 3 of length
int param2; //fizz
int param3; //buzz
System.out.println("Param 1 digit 1 (length)");
param1a = (char) System.in.read();
System.out.println("Param 1 digit 2 (length)");
param1b = (char) System.in.read();
System.out.println("Param 1 digit 3 (length)");
param1c = (char) System.in.read();
System.out.println("Param 2 (fizz)");
param2 = (char) System.in.read();
System.out.println("Param 3 (buzz)");
param3 = (char) System.in.read();
System.out.println("Press e to exe"); //when i press e, print fizzbuzz game
if((char) System.in.read() == 'e') {
runFizzBuzz(param1a,param1b,param1c,param2,param3);
}
}
}
Three side notes: I want this program to do all math in the runFizzBuzz() function, just so I can see it all together. Second, I'm kind of an idiot so please tell me how to add the solution to my script. Last, I've only just learned how to use System.in.read() so forgive me if the solution is obvious!
Thank you for any help I get!