# TOPIC

Not Understanding the Question

#### Tahsin Amin asked 2 years ago

Can someone tell me why for input 8, outout is 4?

Here is my code:

import java.util.Scanner;

public class Main{

``````public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
if (n >= 1 && n <= Math.pow(10, 6)) {
System.out.println(n / 2);
}
}
}``````

}

This topic was solved and cannot recieve new replies.

• #### ๐๐ VICTOR ๐๐CI73A2019 replied 2 years ago

Well.. Firstly !! You don't need to do this codition. if(n >=1 && n<= Math.pow(10,6)) because, this only means that the variable N is gonna be between 1 e 1000000 !! Only it...

Moving on, your logic (n/2) is wrong !! I'll not say the correct logic, but, (n/2) will not work. You must to think in something different.

• #### Tahsin Amin replied 2 years ago

Thank you ๐๐ VICTOR ๐๐CI63A2018.

I thought it was so easy that i haven't checked it with the udebug and gave it for submission. Moreso, this time i didn't write the condition if(n >=1 && n<= Math.pow(10,6)) or if(n >=1 && n<= 1000000)) but, still worked, WHY??

I see that you have explained but, they wiped that line :(