FOR LOOP IS NOT WORKING | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

FOR LOOP IS NOT WORKING

import java.util.Scanner; class Hello{ public static void main (String[] args) { Scanner getage = new Scanner(System.in); System.out.println("Enter your age: ") ; int intgetage = getage.nextInt(); int x= 2018; int y = x - intgetage; for(int i = y; i > x; - - x){ System.out.println(i); } } }

1st Dec 2018, 9:34 AM
ifraz I
ifraz I - avatar
4 Answers
+ 5
ifraz I Hello, 😊 I do not see the purpose to keep your question in the Q/A section if you answered it yourself! In the future, use Code playground to practice, if you can not solve the problem, then ask!👍 Use the search bar! https://www.sololearn.com/post/10362/?ref=app Please, read our guidelines: https://www.sololearn.com/discuss/1316935/?ref=app An useful code for any new user here!;) https://code.sololearn.com/WvG0MJq2dQ6y/
1st Dec 2018, 12:38 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
Got it. Thanks import java.util.Scanner; class Hello{ public static void main (String[] args) { Scanner getage = new Scanner(System.in); System.out.println("Enter your age: ") ; int z = getage.nextInt(); int y = 2018 - z; for(int i = 2018; i >= y; --i){ System.out.println(i); } } }
1st Dec 2018, 9:52 AM
ifraz I
ifraz I - avatar
+ 2
Bennett Post Thanks for the response
1st Dec 2018, 9:54 AM
ifraz I
ifraz I - avatar
0
Tashi N Sorry, Kept on trying, in the class and my lecturer also couldn't get it right. Thats y put it here. But meanwhile, i changed it and it worked. Anyway sorry.
1st Dec 2018, 3:55 PM
ifraz I
ifraz I - avatar