import java.util.*; public class StudentInformation { public static void main (String [] args) { Scanner scan = new Scanner (System.in); System.out.println("Please enter the first number between 0 and 9: "); int num1 = scan.nextInt(); System.out.println("\nPlease enter the second number between 0 and 9: "); int num2 = scan.nextInt(); System.out.println("\nPlease enter your operator: + for ADDITION, - for SUBTRACTION, * for MULTIPLICATION,"); System.out.println("/ for DIVISION, or ^ for EXPONENTIATION: "); String operation = scan.next(); if (num1 < 0 || num1 > 9 || num2 < 0 || num2 > 9) { System.out.println("\nInvalid Number"); } String number1 = num1.toString(); String number2 = num2.toString(); switch (operation) { case "+": System.out.println("The sum of " + number1 + " and " + number2 + " is " + (num1 + num2)); break; case "-": System.out.println("The difference of " + number1 + " and " + number2 + " is " + (num1 - num2)); break; case "*": System.out.println("The product of " + number1 + " times " + number2 + " is " + (num1*num2)); break; case "/": System.out.println("The quotient of " + number1 + " divided by " + number2 + " is " + (num1/num2)); if(num2 == 0) System.out.println("Cannot divide by 0"); break; case "^": System.out.println("The expontentiation of " + number1 + " to the power of " + number2 + " is " + Math.pow(num1,num2)); break; default: System.out.println(operation + " is not valid."); } } }
I try to compile my code and get an error for
String number1 = num1.toString();
saying int cannot be dereferenced. I do not know how to fix this and any help would be great!
Also when I tried to compile it, it said that the switch (operation) must be an int?