+ 1
What is wrong in this code? Plz help
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner mo = new Scanner(System.in); int y = mo.nextInt(); for ( y= mo.nextInt(); y<30; y++) { System.out.println(y); } } }
2 Answers
+ 8
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner mo = new Scanner(System.in);
int y = mo.nextInt();
for (; y<30; y++)
{ System.out.println(y); }
}
}
// nextInt shouldn't be used inside for loop initialization because input has been acquired prior to the loop structure.
+ 1
you are initializing the same variable(y) twice...