Answer to Question #286928 in Java | JSP | JSF for Dragon

Question #286928

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.


1
Expert's answer
2022-01-15T09:18:58-0500
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog