Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Diego Murray
2,515 PointsBasic Java Homework Error
Question:
Variant of FizzBuzz:
Read an integer from standard input. If number is divisible by 7 or 11, print "Fizz". Otherwise, if number is divisible by 13, print "Buzz". Otherwise, print "FizzBuzz". The output should be only "Fizz", "Buzz", or "FizzBuzz".
Note: an integer x is "divisible" by y whenever x % y == 0, e.g., x % 13 == 0
My Code:
import java.util.Scanner;
public class Fizzbuzz {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Choose a number? ");
int number = in.nextInt();
if(number % 7 == 0 || number % 11 == 0)
{
System.out.println("Fizz");
}
else if(number % 13 == 0)
{
System.out.println("Buzz");
}
else
{
System.out.println("Fizzbuzz");
}
in.close();
}
}
PROBLEM
The program that grades my work plugged in "7" and recieved an output of "Choose a number? Fizz" instead of just "Fizz".
Similar problem occurred with all other test input.
1 Answer
Kevin Faust
15,353 Pointsyour thing is being printed on the same line because your not doing println on your first print statement