为什么变量String类型,即使我将它转换为int?
Why is the variable String type, even though I converted it to int?
变量 int g 应该是一个 int,但在输出时它被当作一个字符串,无法弄清楚是什么问题。
class scantest
{
public static int String_to_Int(String a)
{
int n=Integer.parseInt(a);
return n;
}
public static int brooh()
{
String a="43";
int s=String_to_Int(a);
return s;
}
public static void main()
{
int g=brooh();
System.out.println(g +"\n" +g+1);
}
}
输出
43
431
System.out.println
语句内的所有算术运算(在您的情况下为 +
),必须在括号内完成。
您的打印语句如下所示:
System.out.println(g +"\n" + (g+1));
注意g+1
在括号内
变量 int g 应该是一个 int,但在输出时它被当作一个字符串,无法弄清楚是什么问题。
class scantest
{
public static int String_to_Int(String a)
{
int n=Integer.parseInt(a);
return n;
}
public static int brooh()
{
String a="43";
int s=String_to_Int(a);
return s;
}
public static void main()
{
int g=brooh();
System.out.println(g +"\n" +g+1);
}
}
输出
43
431
System.out.println
语句内的所有算术运算(在您的情况下为 +
),必须在括号内完成。
您的打印语句如下所示:
System.out.println(g +"\n" + (g+1));
注意g+1
在括号内