Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Write a program to find and print count of double digit numbers and count of triple digit numbers and count of other numbers from the list.The process of input terminates when 0 is given as input.

0 votes
asked by Mit

1 Answer

0 votes

A number is a double digit number if it is greater than or equal to 10 and less than or equal 99. Similarly, a number is a triple digit number if it is greater than or equal to 100 and less than or equal 999. If it is neither of these two, then it falls into the other category.

Given below is the program

import java.util.Scanner;

public class CountNumbers {
	public static void main(String[] args) {
		int doubleDigitNumbers = 0;
		int tripleDigitNumbers = 0;
		int otherNumbers = 0;

		Scanner scanner = new Scanner(System.in);
		System.out.println("Enter numbers (Type 0 to terminate): ");
		while (true) {
			int number = scanner.nextInt();
			if (number == 0) {
				break;
			}
			if (number >= 10 && number <= 99) {
				doubleDigitNumbers++;
			} else if (number >= 100 && number <= 999) {
				tripleDigitNumbers++;
			} else {
				otherNumbers++;
			}
		}
		System.out.println("Double digit numbers = " + doubleDigitNumbers);
		System.out.println("Triple digit numbers = " + tripleDigitNumbers);
		System.out.println("Other numbers = " + otherNumbers);
	}
}

Here is a sample output

Enter numbers (Type 0 to terminate): 
9
98
745
983
0
Double digit numbers = 1
Triple digit numbers = 2
Other numbers = 1

 

answered by Ranjith (2,683 points)
...