首页 > 编程语言 > 详细

键盘输入数组,然后输出最大

时间:2015-08-29 21:33:37      阅读:260      评论:0      收藏:0      [点我收藏+]
 1 public class Test01{
 2     public static void main(String[] args) {
 3         ArrayList<Integer> list=new ArrayList<Integer>();
 4         System.out.println("请输入数据:");
 5         while(true){
 6             Scanner sc=new Scanner(System.in);
 7             int num=sc.nextInt();
 8             if(num!=0){
 9                 list.add(num);
10             }else{
11                 System.out.println("over");
12                 break;
13                 
14             }
15             
16         }
17         Iterator<Integer> it=list.iterator();
18         while(it.hasNext()){
19             System.out.print(it.next());
20         }
21         
22         Integer[] i=new Integer[list.size()];
23         list.toArray(i);
24         
25         Arrays.sort(i);
26         System.out.println("the max is: "+i[i.length-1]);
27 
28         
29         
30     }
31 }

 

键盘输入数组,然后输出最大

原文:http://www.cnblogs.com/chengling/p/4769776.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!