Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 java enter 5 numbers and count the occurances of same number inside the offset

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

java enter 5 numbers and count the occurances of same number inside the offset Empty
PostSubject: java enter 5 numbers and count the occurances of same number inside the offset   java enter 5 numbers and count the occurances of same number inside the offset EmptyFri 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
Back to top Go down
https://javafreak.board-directory.net
 
java enter 5 numbers and count the occurances of same number inside the offset
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Programming-
Jump to: