本文介绍了可变动态初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为变量y指定一些值并在控制台上打印的代码,希望代码重新分配值并打印
Code that assigns some value to variable y and prints on console, would want the code to reassign value and print
public class Ifelse { public static void main(String[] args) throws IOException { String d = null ; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("A:" ); String y = reader.readLine(); System.out.print("You entered: " + y); String Word = reader.readLine(); System.out.print("A:" ); String y = reader.readLine(); System.out.print("NowAis: " + z); } }代码表示变量y已经定义,想要将值重新分配给y b $ b 问候 我的尝试: 更改了代码并搜索了java类
the code says variable y is already defined, would want to reassign value to y regards What I have tried: changed code and searched java classes
推荐答案等等。你不能在同一范围内创建两个具有相同名称的变量:系统不知道你打算使用哪一个! And so it is. You can't create two variables with the same name in the same scope: the system wouldn't know which one you meant to use! public static void main(String[] args) throws IOException { String d = null ; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("A:" ); String y = reader.readLine(); System.out.print("You entered: " + y); String Word = reader.readLine(); System.out.print("A:" ); y = reader.readLine(); System.out.print("NowAis: " + y); }
应该修复它。
更多推荐
可变动态初始化
发布评论