import java.util.Scanner;
public class Divisible{
public static void main(String[] args){
//Create Scanner
Scanner input=new Scanner(System.in);
//Prompts user to enter an integer
System.out.print("Enter an integer: ");
int Integer=input.nextInt();
//Display results
if (Integer%5==0 && Integer%7==0)
System.out.println("Is "+Integer+" divisible by 5 and 7? "+(Integer%5==0 && Integer%7==0));
if (Integer%5==0 || Integer%7==0)
System.out.println("Is "+Integer+" divisible by 5 or 7? "+(Integer%5==0 || Integer%7==0));
}
}
This is my code. I want it to display for example I input 10, so the results will be:
Is it divisible by 5 and 7? false
Is it divisible by 5 or 7? true
But my program is only displaying 1 result. Can someone explain please.
I think i've figured it out, I removed the 2 if's statements and it worked:
import java.util.Scanner;
public class Divisible{
public static void main(String[] args){
//Create Scanner
Scanner input=new Scanner(System.in);
//Prompts user to enter an integer
System.out.print("Enter an integer: ");
int Integer=input.nextInt();
//Display results
System.out.println("Is "+Integer+" divisible by 5 and 7? "+(Integer%5==0 && Integer%7==0));
System.out.println("Is "+Integer+" divisible by 5 or 7? "+(Integer%5==0 || Integer%7==0));
}
}
Is the code correct now or is there another way to make it work with the if's statements?
This post has been edited by magicm00n: 18 February 2013 - 03:58 AM

New Topic/Question
Reply



MultiQuote




|