Answer to Question #336678 in Java | JSP | JSF for Nick

Question #336678

Create a program using two-dimensional arrays that searches a number and displays the number of times it occurs on the list of 12 input values.

 Sample input/output dialogue:

            Enter twelve numbers:

       15   20 13 30 35 40 16 18 20 18 20

            Enter a number to search: 20

           Occurrence(s) : 3


1
Expert's answer
2022-05-04T12:39:05-0400
import java.util.Scanner;

public class Answer {
    public static void main(String[] args) {
        int[][] array = new int[12] [1];
        System.out.println("Enter twelve numbers: ");
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < array.length; i++) {
            array[i][0] = scanner.nextInt();
        }
        System.out.print("Enter a number to search:");
        int matcher = scanner.nextInt();
        int ans = 0;
        for (int[] ints : array) {
            if (matcher == ints[0]) {
                ans++;
            }
        }
        System.out.println(" Occurrence(s) : " + ans);
    }
}

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
APPROVED BY CLIENTS