Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Diego Murray
Diego Murray
2,515 Points

Basic Java Homework Debug

How can I debug the following 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");
        }
    }
}

Here are my instructions:

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

2 Answers

Nowp sorry, I don't think you need to add that code... I just tested your code in workspaces and it worked. No problems with your code normally...

I think you have to put 'import java.io.Console;' at the begining of your code to be able to use 'System.out'