vendredi 20 août 2021

Is it possible to use a String if statement to change an integer? [closed]

I'm just having a practise at some java coding and was wondering if there was a way to use a String if else statement to change change an integer, as the following doesn't like the c = a * b

    int a, b, c;

    Scanner sc = new Scanner(System.in);
    System.out.println("Enter first number");
    a = sc.nextInt();
    System.out.println("Enter * + - or / ");
    String d = sc.nextLine();
    System.out.println("Enter second number");
    b = sc.nextInt();
    
    if (d.equals("*")){
        c = a * b;
            
    }
    System.out.println(a + " " + d + " b " + " = " + c);
    
    

Aucun commentaire:

Enregistrer un commentaire