JAVA,输入5个数,输出最大值,用for语句怎么做

如题所述

5个数放在一个数组中,然后定义一个max变量,for循环,依次和max比较,如果比max大,就更新max,循环完了,max中放的就是最大值
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-10-08
int i =0;
System.out.print("Input 5 num :");
Scanner sc = new Scanner(System.in);
int temp,max;
temp = sc.nextInt();
max = temp;
for(;i<4;i++)
{
temp = sc.nextInt();
if(temp > max)
max = temp;
}
System.out.print("Max :"+ max);