This game is like FizzBuzz but with different words as you can see.
I need to print the result of "Nardo" to output(System.out.println
) and to file, when called, at the same time.
I made 2 classes one for FizzBuzz game and the other to sent some text into the file. This one works correctly, but I don't know how to combine it with FizzBuzz Class.
I just called the class OutputToFile into the FizzBuzz, but I don't know how to continue.
1) First Class
public class BaroSello {
private OutputToFile outputfile = new OutputToFile();
for(int i=1; i<input; i++){
if ((i % 3 == 0 && i % 5 == 0))
System.out.println("BaroSello");
else if (i % 3 == 0)
System.out.println("Baro");
else if (i % 5 == 0)
System.out.println("Sello");
else if (i%7==0)
// here I need the output to file and to terminal
System.out.println("Nardo");
else
System.out.println(i);
}
}
2) Second Class
public class OutputToFile {
public static void main(String[] args) {
try {
PrintStream myconsole = new PrintStream(new File("/Users/xxx/Desktop/output.txt"));
System.setOut(myconsole);
myconsole.println("hello");
} catch (FileNotFoundException fx) {
System.out.println(fx);
}
}
}