我正在尝试通过编写一个简单的每周计划程序来自学java,并且我的代码中的if语句让我感到悲伤,这是我的代码:
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Week
{
public static void main(String[] args) throws IOException
{
Scanner inorout = new Scanner(System.in);
System.out.println("Do you want to read or write (r/w)");
String decision = inorout.nextLine();
System.out.println(decision);
if(decision == "r")
{
System.out.println("It has gone into the if");
Scanner namer = new Scanner(System.in);
System.out.println("What is the name of the week you want to read?");
String r = namer.nextLine();
Scanner s = new Scanner(new File(r + ".txt"));
System.out.println("What is Your Name?");
String name = s.nextLine();
System.out.println("Welcome " + name);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我编译使用Drjava并输入"R"的程序是不一样,如果statment运行,我在茫然,什么是错,帮助将大大appriciated
Java中的字符串通常与equals不进行比较==.
| 归档时间: |
|
| 查看次数: |
219 次 |
| 最近记录: |