首页 > 解决方案 > 变量应由java中的某些控制台输入填充

问题描述

当我通过扫描仪输入在控制台 26 中键入时,java 中是否有任何可能性,它会自动在 if 语句中用它们各自的值填充 t2 和 t3?(t2 应该是 3,t3 应该是 2020)

        Scanner in = new Scanner(System.in);         
        String s = in.nextLine(); 

        int t = Integer.parseInt(s);

        System.out.println((Arrays.asList(t, t2, t3)));


标签: java

解决方案


我不完全确定你的问题。这是你要求的吗?

    Scanner in = new Scanner(System.in);         
    String s = in.nextLine(); 

    int t = Integer.parseInt(s);

    if (t == 26) {
        t2 = 3; // assumed that t2 and t3 are int
        t3 = 2020;
    }

推荐阅读