+ 1
What is the problem in this code?
I want to get user input for arry length and its values! https://code.sololearn.com/cjVWHI5Bj2jU/?ref=app
3 Answers
+ 5
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner x= new Scanner(System.in);
int y = x.nextInt();
System.out.println(y);
int[ ] primes = new int [y] ;
for (int n = 0; n< primes.length;n++) {
int z = x.nextInt();
primes[n] = z;
System.out.println(z);
}
for (int t: primes) {
System.out.println(t);
}
}
}
+ 1
x is a scanner object. you have to make another variable to save the user input.
0
Please, can you show me how?
Programanta ludanto



