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 search the highestvalue in two dimensional array

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

java search the highestvalue in two dimensional array Empty
PostSubject: java search the highestvalue in two dimensional array   java search the highestvalue in two dimensional array EmptyMon Feb 09, 2009 4:23 am

Code:


//Created by java freak
//all syntax after the comments are disabled it belongs to other usage of the program
import java.io.*;
public class myarray
{
   public static void main(String args[]) throws IOException
   {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      int number[][] =new int[2][5];
      
      //int choice = 0;
      int index1, index2, index3, index4;
      //boolean gotyou = false;
      //int indexlocation = 0;
      int highestvalue = 0;
      
      try
      {
      for(index1 = 0; index1 < number.length; index1++)
      {
         for(index2 = 0; index2 < number[index1].length; index2++)
         {
            System.out.print("Enter a number: ");
            number[index1][index2]=Integer.parseInt(reader.readLine());
         }
      }
      System.out.println("you enter: " +number[0][0]+ " " + number[0][1] + " "+ number[0][2] + " "+ number[0][3]+ " "+ number[0][4]+
      " "+ number[1][0]+ " "+ number[1][1]+ " "+ number[1][2]+ " "+ number[1][3]+ " "+ number[1][4]);
      //System.out.print("enter your choice: ");
      //choice=Integer.parseInt(reader.readLine());
      for(index3 = 0; index3 < number.length; index3++)
      {
         for(index4 = 0; index4 < number[index3].length; index4++)
         {
            if(number[index3][index4]>highestvalue)
            {   
            //indexlocation = index2;
            highestvalue=number[index3][index4];
            //gotyou = true;
            }   
         }
      }
      //if(gotyou==true)
      //{
         //System.out.println("you choose "+ choice + " " + "and its located at index: " + indexlocation);
         System.out.println("the highest value is: "+ highestvalue);
      //}
      //else
      //{
         //System.out.println("error 1");
      //}
      }
      catch(Exception e)
      {
         System.out.println("error");
      }
   }
}

Back to top Go down
https://javafreak.board-directory.net
 
java search the highestvalue in two dimensional array
Back to top 
Page 1 of 1

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