1个回答
展开全部
分太少了,都没有人帮忙啊
我给你一个完整的程序吧
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MainTest {
public static void main(String[] args) {
int count = 0;
int[] array;
int max = 0;
String s;
try {
System.out.print("请输入这个整数的个数:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
s = br.readLine();
count = Integer.valueOf(s).intValue();
array = new int[count];
System.out.print("/n请接着输入这" + count + "个整数,并以逗号分隔:");
br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = br.readLine();
String[] str = s.split(",");
if (str.length == count) {
for (int i = 0; i < count; i++) {
array[i] = Integer.valueOf(str[i]).intValue();
if (i > 0) {
if (array[i] > array[i - 1]) {
max = array[i];
} else {
max = array[i - 1];
}
}
else{
max=array[i];
}
}
break;
}
System.out.println("你输入的整数不是" + count + "个,请重新输入");
br = new BufferedReader(new InputStreamReader(System.in));
}
} catch (IOException e) {}
System.out.println("你输入的最大的整数是:" + max);
}
}
我给你一个完整的程序吧
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MainTest {
public static void main(String[] args) {
int count = 0;
int[] array;
int max = 0;
String s;
try {
System.out.print("请输入这个整数的个数:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
s = br.readLine();
count = Integer.valueOf(s).intValue();
array = new int[count];
System.out.print("/n请接着输入这" + count + "个整数,并以逗号分隔:");
br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = br.readLine();
String[] str = s.split(",");
if (str.length == count) {
for (int i = 0; i < count; i++) {
array[i] = Integer.valueOf(str[i]).intValue();
if (i > 0) {
if (array[i] > array[i - 1]) {
max = array[i];
} else {
max = array[i - 1];
}
}
else{
max=array[i];
}
}
break;
}
System.out.println("你输入的整数不是" + count + "个,请重新输入");
br = new BufferedReader(new InputStreamReader(System.in));
}
} catch (IOException e) {}
System.out.println("你输入的最大的整数是:" + max);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询