Friday, December 01, 2006

Practical 10 Question 1



import javax.swing.*;
class p10q1 {
public static void main(String[] args) {
int[] intArray = {11,0,10,2,2};
int highest = 0;
String output = "";

for (int i=0; i<intArray.length;i++){

if (intArray[i]>highest)
highest = intArray[i];//11

if (i!= intArray.length-1) //if it is not the last element
output += intArray[i] + ",";
else
output += intArray[i]; //don't put comma

} //end for

// TODO: Use JOptionPane to show results : 1 line
// Hint: use output + highest
JOptionPane.showMessageDialog(null,
"Elements: " + output+
"\nHighest: " + highest);


}//end main
}//end class

No comments: