初学者搞不定Java输入流的关闭

不懂应该在哪设置输入流的关闭,试了几个地方,但接着循环,本来要输入的就直接程序关闭报错。(也就几个地方可以放close(),可总是搞不定)

package Week2;

import java.util.Scanner;

public class homework4_16 {

public static void main(String[] args) {
    String s1 = "Welcome to Java";
    String s2 = "Programming is fun";
    String s3 = "Welcome to Java";
    int i = 1;
    do {
        System.out.print("输入字母编号a-v:");
        Scanner input = new Scanner(System.in);
        String ch = input.nextLine();
        switch (ch) {
        case "a":
            System.out.println(s1 == s2);
            break;
        case "b":
            System.out.println(s2 == s3);
            break;
        case "c":
            System.out.println(s1.equals(s2));
            break;
        case "d":
            System.out.println(s1.equals(s3));
            break;
        case "e":
            System.out.println(s1.compareTo(s2));
            break;
        default:
            continue;
        }
        System.out.print("继续请输入1,退出输入0 :");
        i=input.nextInt();
        while(i!=1&&i!=0) {
            System.out.print("请输入1或0 :");
            i=input.nextInt();
        }
    } while (i == 1);
}

}

建议用加上try-catch-finally,在finally执行关闭流操作即可
try {
}catch(Exception e){
}
finally{
//这里关闭流操作
}

IO的操作建议一定要加上try-catch-finally, 最后在finallyl里关闭IO流。

关闭流的操作如上面两位说的,一般放在finally的方法体重,你上面的操作需要考虑引用的作用域问题。