Question: Let's say I have a number from user, for exemple: 456789.
I know how to print in reverse the number, but I am not sure how I can stop the execution to print only 3 first reversed digits. 
What I mean is that I want to print only 987 from the given number

I have to stop somehow with break; but I am not sure how.

```
public static void main(String[] args) {

    int number= 0;
    int numberInReverse = 0;
    System.out.println("Input a number");
    Scanner sc=new Scanner(System.in);
    numar=sc.nextInt();

    while (number !=0){
        numberInReverse*=10;
        numberInReverse=numar%10;
        number/=10;
        System.out.print(numberInReverse);
    }
}

```

Answer: 
You could follow this algo:

1. modulo the number by 1000
2. reverse it
3. print
You can just convert to into a StringBuilder and use `reverse()` and `substring()`:

```
String result = new StringBuilder()
        .append(numar)
        .reverse()
        .substring(0, 3);
System.out.print(result);

```