lundi 24 octobre 2016

Beginner at Java script, on the last if-else statement, i just cant figure out the "but not both " part

import java.util.*; public class Divisible {

public static void main(String[] args) {
    // Divisible by 5 and 6 or not
    Scanner s = new Scanner(System.in);
    int x;
    System.out.print("Enter an integer: ");
    x = s.nextInt();
    if ((x % 5==0) && (x % 6==0)){
        System.out.print("is "+x+" divisible by 5 and 6? ");
        System.out.print("true");
    }else{
        System.out.print("is "+x+" divisible by 5 and 6? ");
        System.out.print("false");
    }// Divisible by 5 or 6
    if ((x % 5==0) || (x % 6==0)){
        System.out.print("\nIs "+x+" divisible by 5 or 6? ");
        System.out.print("true");
    }else{
        System.out.print("Is "+x+" divisible by 5 or 6? ");
        System.out.print("false");
    }// Divisible by 5 or 6,but not both
    if ((x % 5==0) || (x % 6==0)){ here is my problem, i cant figure out the code for "not both" part 
        System.out.print("Is "+x+" divisible by 5 or 6, but not both? ");  
        System.out.print("true");
    }else{
        System.out.print("Is "+x+" divisible by 5 or 6, but not both? ");
        System.out.print("false");
    }

}

} i know my last if-else statement is wrong, i just cant figure out the coding for the last task witch is "Is "+x+" divisible by 5 or 6, but not both? "

Thank you

Aucun commentaire:

Enregistrer un commentaire