Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get the min/max in this program?

Status
Not open for further replies.

ajteka

Technical User
Feb 17, 2009
1
How do I get the min/max in this Java program?
import java.util.Scanner;

public class Array2x3
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in);

int t[][] = new int [2][3];
t[0][0] = 1;
t[0][1] = 1;
t[0][2] = 1;
t[1][0] = 1;
t[1][1] = 1;
t[1][2] = 1;



System.out.println( "Input the 6 numbers for the 2x3 array");

for (int j = 0; j < t.length; j++) // initialize j no semicolon
for (int k = 0; k < t[j].length; k++) // initialize k no semicolon
t[j][k] = input.nextInt();

System.out.println("\t0\t1\t2\n");

//print the headers
for
(int e = 0; e < t.length; e++)
{System.out.print(e);

//print the rows
for
(int r = 0; r < t[e].length; r++)
System.out.printf("\t%d", t[e][r]);

System.out.println();
}// end for



//determine the sum method

int total = ( t[0][0] + t[0][1] + t[0][2]);
System.out.printf("Total first line sum is: %d\n", total );

}//end main

}//end class array
 
Something like this:

1.- Read 1st number
2.- Max = 1st number
3.- Read numbers until end
4.- If number > Max do Max = Number

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top