Ak Java Freak
Posts : 23 Join date : 2009-02-07
| Subject: java enter 5 numbers and count the occurances of same number inside the offset Fri Apr 03, 2009 1:52 am | |
| - Code:
-
import java.io.*; public class sample { public static void main(String args[]) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int num[]= new int[5]; int index1, count = 0, find = 0;
try { for(int index = 0; index < num.length; index++) { System.out.print("Enter a number: "); num[index]=Integer.parseInt(reader.readLine()); }//end main loop }//end try catch(Exception e) { System.out.println(e.getMessage()+"error"); }//end catch for(index1 = 0; index1 < num.length; index1++) { count = 0; for(int index2 = 0; index2 < num.length; index2++) { if(num[index2]==num[index1]) { find = num[index2]; count++; }//end if statement }//end inner loop System.out.println("number " + find + " found " + count + " time(s) inside the offset"); }//end outer loop
}//end main method }//end class sample
| |
|