这是我的算法,我的目标是设置一个"if语句".看一看:
import java.util.Scanner;
public class apple {
public static void main(String args[]) {
System.out.println("This is occurring right now");
for (float ind = 0; ind <= 0.50; ind += 0.1) {
System.out.println(ind);
}
double find;
if (find = 0.25);
Run Code Online (Sandbox Code Playgroud)
在最后一行,它说"我不能将double转换为boolean".
我该怎么办?(我是一名没有时间完成这项任务的人,就像今天一样)
好的,我看了你所有的提示并提出了:
import java.util.Scanner;
public class apple {
public static void main(String args[]) {
System.out.println("this is occouring right now");
for (float ind = 0; ind <= 0.50; ind += 0.1) {
System.out.println(ind);
}
double find = 0;
if (find == 0.25) {
System.out.println("Group A has been Warned");
} else if (find == 0.30) {
System.out.println("Group A and B need to shut down");
} else if (find == 0.40) {
System.out.println("All Groups (A, B and C) need to shut down");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我认为通过在if那里设置语句,它会在运行时向我显示警告.
如何再次拨打内部输入的内容System.out.println()?
我一直在打印出来......现在怎么样?
扭捏
import java.util.Scanner;
public class apple {
public static void main(String args []) {
Scanner dic = new Scanner(System.in);
System.out.println("type the rate: ");
for (double ind=dic.nextDouble(); ind <=0.50; ind+=0.1){
// include my variables
if (ind == 0.2){
System.out.println("Group A has been Warned");
}else if (ind == 0.3){
System.out.println("Group A and B need to shut down");
}else if (ind == 0.4){
System.out.println("All Groups (A, B and C) need to shut down");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想我正朝着正确的方向前进.唐诺.事情是,我输入了0.2,它显示了两个警告.它应该只显示一个.我想.
if (find == 0.25)- 通过==而不是=分配进行比较.
错误消息表示您正在尝试为布尔值分配double值(这是不可能的)
顺便说一句,由于表示双精度的方式,您的代码可能无法正常工作.如果你想进行精确的双重计算,可以使用BigDecimal或使用ints(你的双倍乘以10或100)