dimanche 22 avril 2018

Loop certain IF statements in java

import java.util.Scanner;

public class main {

    public static void main(String[] args) {
        int number = 0;
        Scanner input = new Scanner(System.in);
        System.out.print("Please enter the number of sides");

        number = input.nextInt();  

    if (number == 1) {
        System.out.println("Circle");
    }

    if (number == 3) {
        System.out.println("Triangle");
    }

    if (number == 4) {
        System.out.println("quadrilateral");

    }

    else {
        System.out.println("Incorrect Input");
}
}

}

Hello, I am trying to use the if statement. Can anyone advise me how to loop if statements? Because I get this as a result for example: circle Incorrect Input.

Also, How could I repeat the scanner so it allowed me to type another input?

Aucun commentaire:

Enregistrer un commentaire