Write a program to store 35 numbers in an array then display how many single digit number, two digits numbers and three digits numbers user has given using linear searching.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[35];
int one = 0;
int two = 0;
int three = 0;
for (int i = 0; i < array.length; i++) {
array[i] = in.nextInt();
if (Math.abs(array[i]) < 10) {
one++;
} else if (Math.abs(array[i]) < 100) {
two++;
} else if (Math.abs(array[i]) < 1000) {
three++;
}
}
System.out.println("One: " + one);
System.out.println("Two: " + two);
System.out.println("Three: " + three);
}
}
Comments
Leave a comment