Why do I see no output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do I see no output?

import java.util.Scanner; public class Mazrab5 { public static void main(String[]args) { Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); for (int i=a++; i<b ; i++) { if ( i%5==0) { System.out.println(i); } } scanner.close(); } }

15th Dec 2021, 4:31 PM
Dorsa
4 Answers
+ 3
Hello Dorsa Your code works. If you enter 0 and 6 for a and b you will get 0 and 5 as output. 0 % 5 = 0 5 % 5 = 0
15th Dec 2021, 4:36 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks a lot for your attention.
15th Dec 2021, 5:23 PM
Dorsa
0
Oh yes! You are right.Thanks a lot. I just checked it again,but i dont know why it says no output on my computer , but it is correct on my phone
15th Dec 2021, 4:53 PM
Dorsa
0
Dorsa Maybe because of a++ I never tested it but I guess it causes troubles and maybe it creates an undefinded situation (it depends on your compiler what happens). To increment i you have i++ But you also change i via a++ I would try to print all numbers and see if you overjump numbers. Btw: I think it is not a good practice to manipulate the start or the end condition while the loop is running.
15th Dec 2021, 5:20 PM
Denise Roßberg
Denise Roßberg - avatar