I started learning Java recently and I ran into this problem. I'm trying to do the FizzBuzz exercise but my I think my scanner is not working. I have this code
Scanner scanner1 = new Scanner (System.in);
System.out.print("Number: ");
int scanner2 = scanner1.nextInt();
if ((scanner2 % 5 == 0) && (scanner2 % 3 == 0))
System.out.println("FizzBuzz");
else if ((scanner2 % 5) == 0){
System.out.println("Fizz");
}
else if ((scanner2 % 3) == 0){
System.out.println("Buzz");
}
else {
System.out.println(scanner2);
}
and whenever I execute it, Netbeans show's up
BUILD SUCCESSFUL (total time: 0 seconds)
without me even entering any value, the scanner basically is not working I have java.util.*
imported and no errors are showing up at all. Thank you very much in advance.
Aucun commentaire:
Enregistrer un commentaire