dimanche 15 septembre 2019

How to fix the problem with If statement used 3 times?

The task is this - "Print "Positive", "Negative" or "Zero" depending on the value of n." I can write the positive and negative part with if, but not the last "zero" part. If I write 0 and then press spacebar, "zero" is shown. But If I write only 0, it gives me error.

import java.util.Scanner; 

public class Main {
public static void main(String[] args) { 

Scanner sc= new Scanner(System.in); 

int n = sc.nextInt(); 
if (n>0){

System.out.println("Positive");}

else if (n<0){

System.out.println("Negative");
}

else if  ( n == 0 ); {

System.out.println("Zero");
}
sc.close();
} 
}

Aucun commentaire:

Enregistrer un commentaire