**Posted By:**
Harbir_Guram

**Posted On:**
Friday, September 6, 2002 11:12 AM

Can someone please send me any ideas how I can caluculate the maximum number of a value using a for loop Ask user for a number (n) (which will be the number of numbers that will follow) Ask the user n times for another number, and ask you go along remember the maximum value that has been entered and print it out. e.g. How many numbers? 3 Number? 42 Number? 18 Number? 24 Result = 42 So far the code does every thing but does not print the result I have tried using the max method in the the Math Class but it does not work. import javax.swing.JOptionPane; import java.io.*; import java.lang.Math.*; public class Test06{ public s

More>>
Can someone please send me any ideas how I can caluculate the maximum number of a value using a for loop

Ask user for a number (n) (which will be the number of numbers that will follow)

Ask the user n times for another number, and ask you go along remember the maximum value that has been entered and print it out.

e.g.

How many numbers? 3

Number? 42

Number? 18

Number? 24

Result = 42

So far the code does every thing but does not print the result I have tried using the max method in the the Math Class but it does not work.

import javax.swing.JOptionPane;

import java.io.*;

import java.lang.Math.*;

public class Test06{

public static void main (String args[]){

String number = JOptionPane.showInputDialog("How many numbers");

int n = Integer.parseInt(number);

System.out.println("How many numbers? " + number);

for(int i=0; i

String input = JOptionPane.showInputDialog("Number ?");

String input2 = JOptionPane.showInputDialog("Number ?");

int result = Integer.parseInt(input);

int result2 = Integer.parseInt(input2);

System.out.println("Number? " + result);

System.out.println("Result = " + Math.max(result, result2));

}

}

}

Please use html tags to format code blocks.

<<Less