我正在读取的文件是一行文本,内容为:M = 1; JMP
我知道三个变量(计算,目标和跳转)正在获取正确的值,就像我将它们打印出if语句之前的那一行一样。即使这样,if语句也不会触发。任何帮助都会很棒。
class test7
{
public static void main(String [] args)
throws IOException
{
Scanner file=new Scanner(new FileReader("assembly.txt"));
String line= file.nextLine();
String computation="";
String destination="";
String jump="";
int firstPosition=0;
int secondPosition=0;
firstPosition=(line.indexOf('='));
secondPosition=(line.indexOf(';'));
computation=line.substring(firstPosition+1, secondPosition);
destination=line.substring(0,firstPosition);
jump=line.substring(secondPosition+1);
System.out.println(computation+" "+destination+" "+jump+"\n");
if (computation=="1") System.out.println("has computation");
if(destination=="M") System.out.println("has destination");
if(jump=="JMP") System.out.println("has jump");
}
}