Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christopher Clemente
- //Comp-171
- //Hw #8
- import java.util.Scanner;
- public class Clas {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Enter the size of the Array.");
- int numCount = 0;
- int size = keyboard.nextInt();
- int [] array = new int[size];
- System.out.println("Enter numbers from 1-100 into the array.");
- int count = 0;
- for (int i = 0; i < size; i++){
- int x = keyboard.nextInt();
- array[count] = x;
- count++;
- }
- for(int i = 0; i<= 100; i++ ){
- for(int z = 0; z < size; z++){
- if(i == array[z])
- numCount++;
- }
- if (numCount ==1){
- System.out.println("The Number " + i+ " occurs " +numCount + " time");
- }
- if (numCount < 2){
- numCount = 0;
- }
- if(numCount >=2){
- System.out.println("The Number " + i+ " occurs " +numCount + " times");
- }
- numCount = 0;
- }
- }
- }
- /*
- Enter the size of the Array.
- 7
- Enter numbers from 1-100 into the array.
- 5
- 23
- 72
- 5
- 23
- 23
- 1
- The Number 1 occurs 1 time
- The Number 5 occurs 2 times
- The Number 23 occurs 3 times
- The Number 72 occurs 1 time
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement