主题:求助:关于输入数组以及排序的问题,请帮忙修改
题目:等待用户输入数组(输入指定字符结束),判断数组max 元素及其出现次数。
谢谢!
我写了部分,但是编译时出安全警告,运行时出现不能读取输入终止的错误,请大家帮忙!
import java.io.*;
import java.util.*;
public class Test{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList al=new ArrayList();
int count=0;
while(!(br.readLine().equals("w")))
{
al.add(Integer.parseInt(br.readLine()));
}
int max = Integer.parseInt(al.get(0).toString());
Iterator iterator = al.iterator();
while (iterator.hasNext())
{
String object =iterator.next().toString();
int temp = Integer.parseInt(object);
// System.out.println(temp);
if (max <= temp)
{
max = temp;
if(max<temp)
{
count=1;
}
else
{
count++;
}
}
}
System.out.println(max);
System.out.println(count);
}
}
谢谢!
我写了部分,但是编译时出安全警告,运行时出现不能读取输入终止的错误,请大家帮忙!
import java.io.*;
import java.util.*;
public class Test{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList al=new ArrayList();
int count=0;
while(!(br.readLine().equals("w")))
{
al.add(Integer.parseInt(br.readLine()));
}
int max = Integer.parseInt(al.get(0).toString());
Iterator iterator = al.iterator();
while (iterator.hasNext())
{
String object =iterator.next().toString();
int temp = Integer.parseInt(object);
// System.out.println(temp);
if (max <= temp)
{
max = temp;
if(max<temp)
{
count=1;
}
else
{
count++;
}
}
}
System.out.println(max);
System.out.println(count);
}
}