Meh*_*Meh 1 java symbols compiler-errors
我一直在为一个小程序编写乐趣,但我收到了这个错误:
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
Run Code Online (Sandbox Code Playgroud)
我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,发现java找不到字符串变量,但为什么呢?定义变量,print语句正确.
stringjava中没有类.有String类.
string dtext = "Two";
Run Code Online (Sandbox Code Playgroud)
应该
String dtext = "Two";
Run Code Online (Sandbox Code Playgroud)
S 必须是资本.
并查看String variable范围.你被限制为If.移动block到顶部,
然后你的代码看起来像
String dtext = "";
if (day == 1) {
dtext = "One";
} else if (day == 2) {
dtext = "Two";
} else if (day == 3) {
dtext = "Three";
} else {
System.out.println("Error, day incorrect.");
}
System.out.println(dtext);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3949 次 |
| 最近记录: |