i m writing a code as homework, the task is to create a code, where the user give a number (for example 4 ) and the output will be all the number from 4 ( the users input ) till the length of array (10), the task is to do just with a for-Statement.
literally i m trying as much i can, but every time the output will be 10 times "0", or the users will have to give as input 10 times the numbers.
here what i wrote the last time before i asked here hel; i ve tried to look for others similar things here or on other sites, but i didn´ find soemthing related specificately to it...
thank you
here the last tentative i ve tried
import java.util.Scanner;
import java.util.Arrays;
public class Arrayspopulate {
public static void main(String[] args) {
Scanner firstnumber = new Scanner(System.in);
int [] array = new int [10];
System.out.println(" Please give the first number");
for (int i = 0; i < array.length; i++){
array[i] = firstnumber.nextInt();
System.out.println(array[i]);
}
}
}
forloop. Don't ask within the loop. 2): Although you can, don't display the array contents until the array is completed. Do that after theforloop using:System.out.println(Arrays.toString(array));. 3): All you should have within theforloop block is:array[i] = firstNumber + i;.