可变动态初始化

编程入门 行业动态 更新时间:2024-10-26 18:27:35
本文介绍了可变动态初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为变量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); }

应该修复它。

更多推荐

可变动态初始化

本文发布于:2023-11-22 23:42:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!