# [HELP]Only one result displaying

Page 1 of 1

## 4 Replies - 517 Views - Last Post: 18 February 2013 - 05:09 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312593&amp;s=b9608a607227c11f4b4af38a0fd9f5d7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 magicm00n

Reputation: 1
• Posts: 114
• Joined: 01-March 12

# [HELP]Only one result displaying

Posted 18 February 2013 - 03:57 AM

```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

Is This A Good Question/Topic? 0

## Replies To: [HELP]Only one result displaying

### #2 farrell2k

• D.I.C Lover

Reputation: 874
• Posts: 2,706
• Joined: 29-July 11

## Re: [HELP]Only one result displaying

Posted 18 February 2013 - 04:08 AM

If a number is divisible by 5 and 7, it is divisible by 5 or 7.

### #3 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: [HELP]Only one result displaying

Posted 18 February 2013 - 04:08 AM

Well, what is happening in your if condition is that it will only be true if both conditions are true

```if(TRUE && FALSE)
{
//this block will be skipped.
}
```

That is because the && operator only returns true if both the operands are true.

regards,
Raghav

This post has been edited by raghav.naganathan: 18 February 2013 - 04:09 AM

### #4 andrewsw

• don't rely on secrecy

Reputation: 6022
• Posts: 23,786
• Joined: 12-December 12

## Re: [HELP]Only one result displaying

Posted 18 February 2013 - 04:12 AM

### #5 magicm00n

Reputation: 1
• Posts: 114
• Joined: 01-March 12

## Re: [HELP]Only one result displaying

Posted 18 February 2013 - 05:09 AM

Okay noted. Thanks guys!!