2
In the code below my variable y asks the user to enter values until y reaches 10, I store the variable x and currently the last information typed is stored (which shows at the end of the code) what I would like to know is how to make an "increment" in var x, storing the information typed in X1, x2, X3. up to X10, as with Y.
import java.util.Scanner;
public class SEP_06_exe2_p1{
public static void main(String args[]){
int x;
int y = 1;
do{
Scanner input = new Scanner(System.in);
System.out.print("Digite o " + y + "º valor: ");
x = input.nextInt();
y = ++y; //incrementa 1 no y
}while( y <= 10);
System.out.print(x);
}
}
This increment you are talking about is called filling an array. If you have x as int you will never be able to save values
– CesarMiguel
From what I understand you’re starting with this language, and without wishing to distort the study plan, I’d like to answer before you can use
Arrays
to resolve this citation?– Cold