我在尝试获取If else if语句中的变量时遇到错误任何帮助都会做,谢谢这里是程序
public class Info {
public static void main(String [] args){
char f,F,c,C,h,H;
Scanner input=new Scanner(System.in);
System.out.print("Enter employee num");
int e_num=input.nextInt();
System.out.print("Enter employee first name");
String e_fname=input.next();
System.out.print("Enter employee surname");
String e_sname=input.next();
System.out.print("Enter employee code C or c,H or h and F or f");
char e_code = input.next().charAt(0);
if(e_code=='f' || e_code=='F') {
System.out.print("Enter employee salary: ");
double salary=input.nextDouble();
e_code=calGrossF();
}
else if(e_code=='c'||e_code=='C'){
e_code=calGrossC();
}
else if(e_code=='h'|| e_code=='H'){
e_code=calGrossH();
}
}//end of main
public static void calGrossF(int f, int F){
}//end of Gross(F)
public static char calGrossC(){
}// end of Gross(C)
public static char calGrossH();{
答案 0 :(得分:1)
您的代码目前存在多种语法错误。
calGrossC()
和calGrossH()
必须根据声明返回char
。目前他们什么也没有回报。e_code=calGrossF();
期望calGrossF()
也返回char
。目前,它已声明返回void
。Scanner
(可能不在代码示例中)。callGross()
需要两个int
参数。你没有在e_code=calGrossF();
中提供任何内容。Java编译器指出了所有这些错误。只需逐个查看错误消息并相应地更正代码。
不是语法,但想在此处注明:
f,F,c,C,h,H
),但从不使用它们。这是一个更正的代码(只是几次占位符):
import java.util.Scanner;
public class Info {
public static void main(String [] args){
Scanner input=new Scanner(System.in);
System.out.print("Enter employee num");
int e_num=input.nextInt();
System.out.print("Enter employee first name");
String e_fname=input.next();
System.out.print("Enter employee surname");
String e_sname=input.next();
System.out.print("Enter employee code C or c,H or h and F or f");
char e_code = input.next().charAt(0);
if(e_code=='f' || e_code=='F') {
System.out.print("Enter employee salary: ");
double salary=input.nextDouble();
e_code=calGrossF( 0, 0 );
}
else if(e_code=='c'||e_code=='C'){
e_code=calGrossC();
}
else if(e_code=='h'|| e_code=='H'){
e_code=calGrossH();
}
}//end of main
public static char calGrossF(int f, int F){
return 'F';
}//end of Gross(F)
public static char calGrossC(){
return 'C';
}// end of Gross(C)
public static char calGrossH(){
return 'H';
}
}
答案 1 :(得分:0)
首先,你有public static void calGrossF(int f,int F)as“void”
你将它的价值存储在e_code中
并且在调用
答案 2 :(得分:0)
//Method Statement
public char calGrossF(String name, int emp_num, double gross_sal, double fix_sal, double
ded, double net_pay, double highest_sal, double lowest_sal,
char ch)
{
//return statement
return calGrossF(name, emp_num, gross_sal, fix_sal, ded, net_pay, highest_sal, lowest_sal, ch);
}