import javax.swing.JOptionPane;
import java.util.Scanner;
public class pay{
static Scanner sc;
public static void main (String[]args)
{
double Regpay = 8;
double OThour = Regpay * 1.5;
double hours = 0;
double gpay = Regpay * hours;
double Totalpay = OThour + gpay;
Scanner input = new Scanner(System.in);
System.out.println("Normal pay for hours worked less than 40hrs will be, £8.00 per hour");
System.out.println("If workers work more than 40hrs, their pay will be time and a half");
System.out.println("please enter your name");
String name = sc.nextLine();
System.out.println("How many hours did you work this month");
hours = sc.nextDouble();
System.out.println("How many hours overtime did you work");
OThour = sc.nextDouble();
if (hours<=40){
Totalpay = gpay;
System.out.print("You are not entitled to overtime pay");
}else{
if (hours>=41)
Totalpay = gpay + OThour >=1;
}
}
}
我收到錯誤就行了Totalpay = gpay + OThour >=1;
我不知道該怎麼辦,我一直試圖改變周圍的事情,但我不斷收到同樣的錯誤!!!!不兼容類型:布爾不能轉換爲double(錯誤)
你想用這條線完成什麼?看起來你正在比較'gpay + OThour',看它是否大於或等於'1'。 – rgettman
'gpay + OThour> = 1'檢查'gpay + OThour'是否大於或等於1,並返回'true'或'false',由於它不是一個'double'數。 –