Question 13
Write a program in Java to input two numbers and print their sum. Also pro
whether their sum is a single digit or a double dipit or more than a double digit
number.
15
Answers
Answer:
import java.util.*;
class Digits {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the first digit:");
int dig1 = sc.nextInt();
System.out.println("Please enter the second digit:");
int dig2 = sc.nextInt();
int sum = dig1 + dig2;
int numOfDigs = 0;
while(sum != 0){
sum /= 10;
numOfDigs++;
}
if(numOfDigs == 1) {
System.out.println("Sum is a single digit number");
}
else if(numOfDigs == 2) {
System.out.println("Sum is a double digit number");
}
else {
System.out.println("Sum is more than a double digit number");
}
}
}
Hope it helps!