题目
Description
给定很多行数据,要求输出每一行的最大值.
Input
程序有多行输入,每一行以0结束.
Output
有多行输出,对应输入的行数.
Sample Input
23 -456 33 78 0
43 23 987 66 -137 324 0
544 27 7 9 102 234 -44 -732 723 0
Sample Output
78
987
723
代码块
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cn = new Scanner(System.in);
while(cn.hasNext()){
int[] a = new int[1001];
int i =0;
for(;;i++){
a[i] = cn.nextInt();
if(a[i]==0) break;
}
int max = a[0];
for(int j =0;j<i;j++){
if(max<a[j]) max = a[j];
}
System.out.println(max);
}
}
}