我一直在编码一个有趣的小程序,但我已经收到此错误:
Compilation error time: 0.11 memory: 380672 signal:0Main.java:22:
error: cannot find symbol
string dtext = "One";
^
symbol: class string
location: class Ideone
Main.java:37: error: cannot find symbol
System.out.println(dtext);
^
symbol: variable dtext
location: class Ideone
2 errors
我的代码:
import java.util.*;
import java.lang.*;
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
import java.lang.String;
class Ideone
{
public static void main (String str[]) throws IOException
{
Scanner sc = new Scanner(System.in);
//System.out.println("Please enter the month of birth");
//int month = sc.nextInt();
System.out.println("Please enter the day of birth");
int day = sc.nextInt();
//day num to day text
if (day == 1)
{
string dtext = "One";
}
else if (day == 2)
{
string dtext = "Two";
}
else if (day == 3)
{
string dtext = "Three";
}
else
{
System.out.println("Error, day incorrect.");
}
System.out.println(dtext);
}
}
我做了一些研究,发现的java无法找到字符串变量,但是为什么呢? 该变量定义,打印说法是正确的。