Question

java program: Write a program which displays the following list on the screen and asks the...

java program:

Write a program which displays the following list on the screen and asks the user to enter either 1 or 2 and perform one of the operations based on the user’s input. If the user enters any other character other than 1 or 2 then display “wrong choice”.

LIST OF OPERATIONS

1. Buzz Number

                     2. Consecutive Odd numbers

Note:

A BUZZ number is a number which either ends with 7 or is divisible by 7.

Sample input

27

Output

27 is a Buzz number

Sample input:

46

Output:

46 is not a Buzz number

Two numbers are said to be consecutive odd numbers if both the numbers are odd and the difference between them is 2.

Sample input

11

15

Output:

11 and 15 are not consecutive odd numbers

Sample input

21

23

Output:

21 and 23 are consecutive odd numbers

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

8 { 1 import java.util.Scanner; 2 3 - public class MyClass 4 public static void main(String args[]) { 5 Scanner sc = new Scan

Enter either 1 or 2: 1 Enter a number: 27 27 is a Buzz number

import java.util.Scanner;

public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
  
System.out.print("Enter either 1 or 2: ");
int choice = sc.nextInt();
  
if(choice != 2 && choice != 1)
System.out.print("wrong choice");
else
{
if(choice == 1)
{
System.out.print("Enter a number: ");
int n = sc.nextInt();
if(n%7 == 0 || n % 10 == 7)
System.out.print(n + " is a Buzz number");
else
System.out.print(n + " is not a Buzz number");
}
else
{
System.out.print("Enter a number: ");
int a = sc.nextInt();
int b = sc.nextInt();
  
if((a+2 == b || b+2 == a) && a%2 == 1)
System.out.print(a + " and " + b + " are consecutive odd numbers");
else
System.out.print(a + " and " + b + " are not consecutive odd numbers");
}
}
}
}

// Please up vote

Add a comment
Know the answer?
Add Answer to:
java program: Write a program which displays the following list on the screen and asks the...
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
  • write a java program that displays the following: Write a Java program that prompts the user...

    write a java program that displays the following: Write a Java program that prompts the user to enter an integer and determines whether 1. it is divisible by 5 and 6, whether on 2. it is divisible by 5 or 6, 3. it is divisible by 5 or 6, but not both. Here is a sample run of this program: Sample run: Enter an integer: 10 Is 10 divisible by 5 and 6? false Is 10 divisible by 5 or...

  • Write a Java program called Histogram.java that displays a list of distinct characters in an input...

    Write a Java program called Histogram.java that displays a list of distinct characters in an input tile and the occurrence of each eharacte. Your iogram should 1ead an input file name from a use. After that, your program should read characters in the file and display a list of distinct characters and their occurTeces. Finally, your program should draw a veril bafo the occuences For the assignment, your program has.to display the result exactly as the sample run. For instance,...

  • Write a program using M.I.P.S that asks user “how many positive number that is devisable by...

    Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...

  • Create a JAVA program that in two numbers from user input, the program then does the...

    Create a JAVA program that in two numbers from user input, the program then does the following arithmetic calculations. The program will run in ascending order if the first number is small and in descending order of the first number is bigger. The program then alternates between addition(ODD) and subtraction(EVEN) depending on the previous number see examples below   [15] Sample run 1: Enter two numbers: -3 2 Output: The following arithmetic calculations were performed : Arithmetic operations = (-3) +...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a...

    USING PYTHON LANGUAGE. QUESTION I: Write a program that displays the following table: a a^2 a 3 a14 1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 QUESTION II: An approximate value of a number can be computed using the following formula: 7 ) Write a program that displays the result of 4 X + 7 • H) and 4 X - 를 7 tis). 9 QUESTION III: Write a program that prompts...

  • Write a program that asks the user to enter number, and displays all the numbers that...

    Write a program that asks the user to enter number, and displays all the numbers that are multiples of 2 and 5 smaller than or equal to the number entered by the user. Hint: A number n is a multiple of 2 if the remainder of the division of n by 2 is equal to zero. Your program should have an output similar to the following: Please enter a number: 50 The multiples of 2 and 5 less than or...

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • Question 4 (3 mark) : Write a Java program to ask the user to input an...

    Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...

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
ADVERTISEMENT