Trying to build a calculator in java but I keep getting the .class error -
i started java class summer program offering , tasked creating simple calculator. have different cases created , variables accounted reason keep getting .class error , have no clue know comes from:
cases(int fnum, int snum, string op);
import java.util.scanner; public class day1{ public static void main(string [] args){ cases(int fnum, int snum, string op); } public static void input(){ scanner userinput = new scanner(system.in); int fnum, snum; string op; system.out.println("enter first num: "); fnum = userinput.nextint(); system.out.println("enter second num: "); snum = userinput.nextint(); system.out.println("enter operation: "); op = userinput.next(); } public static void cases(int fnum, int snum, string op){ input(); switch(op){ case "+": system.out.println(fnum + snum); break; case "-": system.out.println(fnum - snum); break; case "*": system.out.println(fnum * snum); break; case "/": system.out.println(fnum / snum); break; default: system.out.println(fnum % snum); break; } } }
change code this.
import java.util.scanner; public class day1{ public static void main(string [] args){ int fnum = 5; int snum = 5; string op = ""; input(fnum, snum, op); } public static void input(int fnum, int snum, string op){ scanner userinput = new scanner(system.in); system.out.println("enter first num: "); fnum = userinput.nextint(); //rest of code cases(fnum, snum, op); } public static void cases(int fnum, int snum, string op){ //your code } }
you needed declare variables pass them function cases function can reference them. think teacher means keep things out of main don't input , cases code inside of main()
. instead teacher wants use functions, you're doing.
Comments
Post a Comment