. Write a java program
Answers
Answer:
Scope of the program: To identify input number is buzz or not
A number is called a buzz number if it is :
1. Divisible by 7 or
2. Ends with 7
Explanation:
import java.util.Scanner;
public class Example {
public static void main(String[] args) {
//1 variable no to store the user input value
int no;
Scanner sc;
//2 strings will be used for customizing the final result output
String isBuzzNo = " is a buzz number as";
String strDivisibleBy7 = " it is divisible by 7";
String strEndsWith7 = " ends with 7";
//3 to enter a number that is required to check.
sc = new Scanner(System.in);
System.out.println("Enter a number you want to check : ");
//4
no = sc.nextInt();
//5 if-elseif-else condition to check if the number is buzz or not.
if (no % 10 == 7) {
//6
if (no % 7 == 0) {
System.out.println(no + isBuzzNo + strDivisibleBy7 + " and" + strEndsWith7);
} else {
System.out.println(no + isBuzzNo + " it" + strEndsWith7);
}
} else if (no % 7 == 0) {
//7
System.out.println(no + isBuzzNo + strDivisibleBy7);
} else {
//8
System.out.println(no + " is not a buzz number");
}
}
import java.util.Scanner;
public class Example {
public static void main(String[] args) {
//1 variable no to store the user input value
int no;
Scanner sc;
//2 strings will be used for customizing the final result output
String isBuzzNo = " is a buzz number as";
String strDivisibleBy7 = " it is divisible by 7";
String strEndsWith7 = " ends with 7";
//3 to enter a number that is required to check.
sc = new Scanner(System.in);
System.out.println("Enter a number you want to check : ");
//4
no = sc.nextInt();
//5 if-elseif-else condition to check if the number is buzz or not.
if (no % 10 == 7) {
//6
if (no % 7 == 0) {
System.out.println(no + isBuzzNo + strDivisibleBy7 + " and" + strEndsWith7);
} else {
System.out.println(no + isBuzzNo + " it" + strEndsWith7);
}
} else if (no % 7 == 0) {
//7
System.out.println(no + isBuzzNo + strDivisibleBy7);
} else {
//8
System.out.println(no + " is not a buzz number");
}