解决方案 »

  1.   

    for循环很可能死循环   没有跳出语句
      

  2.   

    也有健壮性问题吧
    //Testimport java.util.*;class Main {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while(scanner.hasNext()) {
    int temp = 0;
    String str = null;
    try{
    str = scanner.nextLine();
    temp = Integer.parseInt(str);;

    while(temp >100000 || temp <0) {
    System.out.println("Please input a number between 0 and 100000!");
    str = scanner.nextLine();
    temp = Integer.parseInt(str);
    }
    }catch(NumberFormatException e) {
    System.out.println("You must input a number!");
    e.printStackTrace();
    }

    int num = 0;
    while(temp != 1) {

    if(temp % 2 == 0) {
    temp = temp / 2;
    }else {
    temp = (3*temp+1) / 2;
    }
    num ++;
    }
    System.out.println("num = " + num);
    }
    }
    }