vendredi 6 décembre 2019

Why are difference bt. even and odd displays?

I've got something strange here with display.

The code System.out.println("");

works perfectly with odd numbers only, but not with even numbers. Why?

Thanks!

Check the below code:

import java.util.*;
public class oddeven{
    public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    System.out.println("Odd or Even? Please insert:");
    int number = in.nextInt();
    if(number > 0 && number % 2 == 1){
        System.out.println(""); // does not work with even, WHYWHYWHY
        System.out.println("Number " + number + " is odd.");
        } else {
        System.out.println("Number " + number + " is even.");
        }
    } 
}



Aucun commentaire:

Enregistrer un commentaire