如果没有得到输出,则使用java嵌套
编译和运行时,我没有得到任何输出。当成本低于100且评分为4时,尝试获得推荐的输出。如果有其他方法,请存钱
System.out.print("Enter cost: ");
double cost = input.nextDouble();
System.out.println("Enter a Star value between 1-4");
int rating = input.nextInt();
if (cost < 100){
if (rating == 4 )
System.out.println("Recommended");
}
else
System.out.println("Save your money");
# 1 楼答案
如果您只想在评级为4且成本为<;100那么你可以这样做:
# 2 楼答案
这有点像根本不需要给出两个if循环。你可以拥有&&;一次if循环的操作员
这是理想的解决方案,在没有必要的情况下,给予if两次又有什么意义呢
你仍然需要同样的方法来使用这个