
确实主方法需要有static修饰的,没有static的main方法并不是真的主方法没法运行。如果是印刷错误,本意是public static void main的话,结果就是:
What a pleasure!
I amTom
How do you do
public
class
TestTest
{
public
static
String
changeStr(String
str){
str="welcome";
return
str;
}
public
static
void
main(String[]
args)
{
String
str="1234";
Systemoutprintln(changeStr(str));
}
}
这样写就输出welcome了,原因是你在main主函数中使用Systemoutprintln时调用的是main函数里的str,而不是changeStr方法里的str。
import javautilScanner;
public class Test {
public static void main(String[] args) {
Scanner input=new Scanner(Systemin);
Systemoutprintln("输入第一个数");
double x=inputnextDouble();
Systemoutprintln("输入第二个数");
double y=inputnextDouble();
Systemoutprintln("输入运算符");
String op=inputnext();
if ("+"equals(op)) {
Systemoutprintln("结果是:"+(x+y));
}else if ("-"equals(op)) {
Systemoutprintln("结果是:"+(x-y));
}else if (""equals(op)) {
Systemoutprintln("结果是:"+(xy));
}else if ("/"equals(op)) {
Systemoutprintln("结果是:"+(x/y));
}else {
Systemoutprintln("出现异常");
}
}
}
以上就是关于分析下面Java程序,写出该程序运行的结果全部的内容,包括:分析下面Java程序,写出该程序运行的结果、写出java程序的结果,并解释原因。、输入两个数然后输入一个运算符计算出结果输出的JAVA程序怎么写等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)