有没有办法改变java变量声明? [重复]

问题描述 投票:0回答:0
//imports
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    //vars
    double x = 5;
    Boolean y = true;

    while (y){
        String x = sc.nextLine();
        y = false;
    }

    System.out.println(x); // x should output the String but doesn't. 
    //how do I fix this or is there a different way?
    }
}

如果有帮助,我正在处理的实际代码。

https://replit.com/@AlexanderJensen1024/Tests#Main.java

我试图将变量设为 null 以回答别人的问题。

java variable-declaration
© www.soinside.com 2019 - 2024. All rights reserved.