# [HELP]Only one result displaying

Page 1 of 1

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

### #1 magicm00n

• D.I.C Head

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.
Was This Post Helpful? 1

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

Was This Post Helpful? 1

### #4 andrewsw

• blow up my boots

Reputation: 6546
• Posts: 26,533
• Joined: 12-December 12

## Re: [HELP]Only one result displaying

Posted 18 February 2013 - 04:12 AM

Please don't name your integer Integer
Was This Post Helpful? 1

### #5 magicm00n

• D.I.C Head

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!!
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }