write a program to enter phone number calculate and display the sum and the average of a number using scanner class in Java
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class KboatMagicNum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number to check: ");
int num = in.nextInt();
int n = num;
while (n > 9) {
int sum = 0;
while (n != 0) {
int d = n % 10;
n /= 10;
sum += d;
}
n = sum;
}
if (n == 1)
System.out.println(num + " is Magic Number");
else
System.out.println(num + " is not Magic Number");
}
}
OUTPUT
Similar questions
Math,
3 months ago
English,
3 months ago
Business Studies,
6 months ago
Social Sciences,
6 months ago
Math,
11 months ago
Environmental Sciences,
11 months ago
Economy,
11 months ago