Question

I need this code in Java! Start by read in a number from the user that...

I need this code in Java!

Start by read in a number from the user that is in the range 1-200. If the user inputs a number out of that range, print out: Invalid number, and end the program.

Next,

If a number is divisible by 3, print Fizz instead

If a number is divisible by 5, print Buzz instead

If a number is divisible by both 3 and 5, print out FizzBuzz

If a number is none of the above, print the number itself.

Hint: What's the remainder if a number n is divisible by number m? That is, what would be the result of n % m?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class FizzProgram {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number from 1-200: ");
       int num = sc.nextInt();
       if(num<1 || num>200)
       {
           System.out.println("Invalid number");
           return;
       }
       // checking if it is div30isable by 3
       if (num % 3 == 0)
           System.out.println("Fizz");
       if (num % 5 == 0)
           System.out.println("Buzz");
       if (num % 3 == 0 && num % 5 == 0)
           System.out.println("FizzBuzz");
       if (num % 3 != 0 && num % 5 != 0)
           System.out.println(num);
   }
}

Add a comment
Know the answer?
Add Answer to:
I need this code in Java! Start by read in a number from the user that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (1) Read in a number from the user that is in the ranger 1-200. If the...

    (1) Read in a number from the user that is in the ranger 1-200. If the user inputs a number out of that range, print out:Invalid number, try again. and read in a number until a valid one is produced. (2) Print out the numbers from 1 to userInput but: If a number is divisible by 3, print Fizz instead If a number is divisible by 5, print Buzz instead If a number is divisible by both 3 and 5,...

  • Write a perl program that prompts a user for a number and checks that number against...

    Write a perl program that prompts a user for a number and checks that number against three possibilities. If the number is divisible by 3, it should print fizz, if its divisible by 5 it should print buzz, and if its divisible by 3 and 5 it should print fizzbuzz. It should do nothing if none of those conditions are met. I need help with this.

  • MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an...

    MULIMI Umplicated than the hrst assignment. Write a program that will let the user enter an integer. If the integer is less than 5 make the actual input value be 50. We will call the value that the user put in N. Print the integers from 1 to None number on each line. If the number you are going to print is divisible by 3 print the word fuzz instead of the number. If the number is divisible by 5...

  • LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10...

    LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10 10.201.51. eRAD D scheduling山UitPro 6 Fizz Buzz Write a function "void FizzBuzz(int n)" that lists all of the numbers from 1 to n, but replace all numbers divisible by 3 but not divizible by 5 with the word "Fizz", replace all numbers divisible by 5 but not divisible by 3 with the word "Buzz", and replace all numbers divisible by both 3 and 5...

  • java programming. hint: please use if-else method. Need to print numbers 1..100 For multiples of 3,...

    java programming. hint: please use if-else method. Need to print numbers 1..100 For multiples of 3, print "Fizz" instead of the number For multiples of 5. print "Buzz" instead of the number For multiples of 3 and 5, print "FizzBuzz" instead of the number For others, just print the number.

  • Python: Using your favorite text editor, write a program that outputs the string representation of numbers...

    Python: Using your favorite text editor, write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Submit by uploading a .py file Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"...

  • HELLO EXPERTS, I need a code for this 4 questions.... it's make me crazy now... could...

    HELLO EXPERTS, I need a code for this 4 questions.... it's make me crazy now... could you guys help me please? it's java Given two strings, word and a separator sep, return a big string made of count occurrences of the word, separated by the separator string. repeatSeparator("Word", "X", 3)- "WordXWordXWord" repeatSeparator("This", "And", 2)- "ThisAndThis" repeatSeparator("This", "And", 1)- "This"| For example: Result Test System.out.println(repeatSeparator("Pa", "Tn", 4)); PaTnPaTnPaTnPa Consider the series of numbers beginning at start and running up to but...

  • c++ language Consider the series of numbers beginning at user-specified start and running up to but...

    c++ language Consider the series of numbers beginning at user-specified start and running up to but not including user-specified end, so for example start=1 and end=5 gives the series 1, 2, 3, 4. Return a new string[] array containing the string form of these numbers (e.g. "one", "two", "fifty-three" etc., except for multiples of 3, use "Fizz" instead of the number, for multiples of 5 use "Buzz", and for multiples of both 3 and 5 use "FizzBuzz". Test with numbers...

  • I need a code and its java Blue jay please its almost due Week 8 Quiz...

    I need a code and its java Blue jay please its almost due Week 8 Quiz Submitting a file upload File Types pdf Due Friday by 11:30am Points 10 Available after Oct 25 at 10:45am With your team, write a program that inputs a 3-digit integer, like 731. Then the program should multiply the number by 1001, which would make 731 become 731731. Next, write a for loop with the following header: for (int i =7;i<=13; i+=2) In the for...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT