Advertisement
RazorBlade57

hw8

Nov 8th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. //Christopher Clemente
  2. //Comp-171
  3. //Hw #8
  4.  
  5.  
  6. import java.util.Scanner;
  7. public class Clas {
  8.  
  9.     public static void main(String[] args) {
  10.        
  11.         Scanner keyboard = new Scanner(System.in);
  12.        
  13.         System.out.println("Enter the size of the Array.");
  14.        
  15.        
  16.         int numCount = 0;
  17.         int size = keyboard.nextInt();
  18.         int [] array = new int[size];  
  19.                
  20.         System.out.println("Enter numbers from 1-100 into the array.");
  21.        
  22.         int count = 0;
  23.        
  24.         for (int i = 0; i < size; i++){
  25.             int x = keyboard.nextInt();
  26.             array[count] = x;
  27.             count++;
  28.         }
  29.        
  30.         for(int i = 0; i<= 100; i++ ){
  31.             for(int z = 0; z < size; z++){
  32.                 if(i == array[z])
  33.                     numCount++;
  34.  
  35.             }
  36.             if (numCount ==1){
  37.                 System.out.println("The Number " + i+ " occurs " +numCount + " time");
  38.            
  39.             }
  40.             if (numCount < 2){
  41.                 numCount = 0;
  42.                
  43.             }
  44.             if(numCount >=2){
  45.             System.out.println("The Number " + i+ " occurs " +numCount + " times");
  46.             }
  47.             numCount = 0;
  48.        
  49.        
  50.         }
  51.                
  52.     }
  53.  
  54. }
  55.        
  56. /*
  57.         Enter the size of the Array.
  58.     7
  59.     Enter numbers from 1-100 into the array.
  60.     5
  61.     23
  62.     72
  63.     5
  64.     23
  65.     23
  66.     1
  67.     The Number 1 occurs 1 time
  68.     The Number 5 occurs 2 times
  69.     The Number 23 occurs 3 times
  70.     The Number 72 occurs 1 time
  71.  
  72.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement