zoukankan      html  css  js  c++  java
  • 异常练习

    package ltb6w;
    import java.util.*;
    import java.util.ArrayList;
    
    public class TestInteger {
    
    private int number;
    private List<Integer> list=new ArrayList<Integer>();
    
    
    Scanner sc=new Scanner(System.in);
    public TestInteger() {
    
    System.out.println("请输入10个成绩");
    
    } 
    
    public void setSort() {
    
    
    int i=0;
    
    while (i<10) {
    
    try {
    
    number=sc.nextInt();
    
    }catch(InputMismatchException e) {
    
    System.out.println("输入的数据类型不同,注意输入整数。");
    
    break;
    }
    
    System.out.println("第"+(i+1)+"个数:"+number);
    
    if(number==1982) {
    break;
    }else if (number<0) {
    
    System.out.println("不要输入负数");
    
    break;
    
    }
    
    list.add(number);
    
    i++;
    
    
    }
    
    System.out.println("结束,输完。");
    
    this.getSort();
    
    }
    
    public void getSort() {
    
    
    Collections.sort(list);
    
    for(int j=list.size()-1;j>=0;j--) {
    
    try {
    
    System.out.println("成绩:["+(j+1)+"]"+list.get(j));
    
    }catch(Exception e) {
    
    System.out.println("数组越界异常"+e.getMessage());
    
    }
    }    
    }
    
    public static void main(String[] args) {
    
    TestInteger te=new TestInteger() ;
    
    te.setSort();
    
    }
    
    }
  • 相关阅读:
    113. Path Sum II
    112. Path Sum
    111. Minimum Depth of Binary Tree
    110. Balanced Binary Tree
    Create
    SetWindowPos
    INT_PTR数据类型
    SDK介绍
    COLORREF
    setfont()函数
  • 原文地址:https://www.cnblogs.com/ltb6w/p/8011065.html
Copyright © 2011-2022 走看看