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

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'