# 3 digit numner?

Page 1 of 1

## 5 Replies - 709 Views - Last Post: 09 October 2012 - 10:30 PMRate 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=294982&amp;s=586278c86bb217e60f5328d9cc851df2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 amture106

Reputation: -1
• Posts: 159
• Joined: 08-September 11

# 3 digit numner?

Posted 09 October 2012 - 07:06 PM

Hey guys,

I'm writing a program that does a lot of things, but one of them is to check if the user input a 3 digit number then do stuff, but if a user input 2 or 4+ digit numbers then the program don't do any thing.

I wrote this chunk of code
```do{
System.out.println("Enter a 3-digit number: ");
int input = scan.nextInt();
}while (input >= 100 || input < 1000);
```

but it doesn't check if the input is 3 digits.

This post has been edited by amture106: 09 October 2012 - 07:07 PM

Is This A Good Question/Topic? 0

## Replies To: 3 digit numner?

### #2 Kinaces

Reputation: 78
• Posts: 230
• Joined: 04-October 12

## Re: 3 digit numner?

Posted 09 October 2012 - 07:26 PM

Well first this will not even compile. How can you check a condition on a variable that will only be created if the condition is true. You need to make input outside of the do/while loop. You do not have to instantiate it outside of the loop, just make the variable outside the loop. Second of all, you're testing if input IS a 3 digit number, and as long as it is keep getting input.

### #3 amture106

Reputation: -1
• Posts: 159
• Joined: 08-September 11

## Re: 3 digit numner?

Posted 09 October 2012 - 07:48 PM

```int input;
do{
System.out.println("Enter a 3-digit number: ");
input = scan.nextInt();
}while (input >= 100 || input < 1000);

```

now it will compile and still won't work

### #4 Zoquo

Reputation: 20
• Posts: 45
• Joined: 16-May 12

## Re: 3 digit numner?

Posted 09 October 2012 - 08:10 PM

If you are trying to check to see if it is a three-digit number, the condition would be AND not OR.

But if you are checking to see if it is NOT, then just change the OR to an AND and throw a NOT before it.

This post has been edited by Zoquo: 09 October 2012 - 08:13 PM

### #5 burakaltr

• D.I.C Regular

Reputation: 91
• Posts: 280
• Joined: 07-November 10

## Re: 3 digit numner?

Posted 09 October 2012 - 08:13 PM

```import java.util.Scanner;

public class Digit {
public static void main(String...h){
int input=333;
Scanner scan=new Scanner(System.in);
boolean b=true;
while ( b ){

System.out.println("Enter a 3-digit number: ");
input = scan.nextInt();
b =!(input >= 100 && input < 1000);
}
//execution block goes here !
}
}

```

This post has been edited by burakaltr: 09 October 2012 - 08:23 PM

### #6 CasiOo

• D.I.C Lover

Reputation: 1575
• Posts: 3,541
• Joined: 05-April 11

## Re: 3 digit numner?

Posted 09 October 2012 - 10:30 PM

I like that both of you suggested putting a not around it

Why not just
```do {