最近在玩judge:题目入下,要求用java哦~
Find the maximum element in a set of integers. List of integers ends with EOF. Intergers are separated by whitespace characters (SPACE, TAB, NEWLINE). There are at most 10000 integers in the list, their modulii being less than 2 to 30 power (2 30).我的代码(没通过judge,问题是解决了,就是要在输入数字时以一个非int型字符来结束输入) 
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int bigest=0;
Scanner in=new Scanner(System.in);
while(in.hasNextInt()&&(in.)){
int temp=in.nextInt();
if(temp>bigest){
bigest=temp;
}
}
System.out.println("the bigest is:"+bigest);

}}

解决方案 »

  1.   

    你可以通过判断输入字符得ascii码,只要不在数字范围内的就结束
      

  2.   

    To:
       sheep219(sheep219)
       如何具体判断
       冒泡,我是读取一个,比较一个了,难道还有更简单的?
      

  3.   

    import java.util.Arrays;
    public class test {
    public static void main(String[] args) {
    Arrays.sort(args);
    System.out.println("the bigest is:"+args[args.length-1]);
    }
    }
      

  4.   

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at test.main(test.java:5)
    刨除异常了~
      

  5.   

    那是因为你没有在运行之间把你要排序的数字输入进取,你不是要对输入的数字进行排序吗?当然要先输入了。
    如果你是在dos提示符向运行的话:
                        java test 3 8 1 9 4 2 7 5
      

  6.   

    我的程序问题是解决了,就是要在输入数字时以一个非int型字符来结束输入
    所以想问说如何解决“以回车来结束这组数字的输入”
      

  7.   

    程序在输入的过程中就在排序了,即每次输入一个数就与当前的bigest比较,先前的不是最大数的数字则可以丢弃掉,因为最后只要输入那个最大数就可以了
      

  8.   

    不是用EOF来结束的吗?
    那么in.hasNextInt()就可以结束了啊
      

  9.   

    > “以回车来结束这组数字的输入”回车不能结束啊!题目不是说,NEWLINE 是分隔符吗?
      

  10.   

    To:f_acme(沧海一声笑) 
        但是我无法结束阿,你可以上机调试下看看的,输入完后还是在那里等待的
      

  11.   

    EOF 是指什么?三个大写字母吗?我试过了,能结束。倒是楼主给的程序编译不通过,需要把【&&(in.)】去掉才行。