0
how to input a variable in java
2 Answers
+ 1
Scanner sc = new Scanner(System.in);
int c = sc.nextInt();
sc.close();
above code will wait until the user enters a Integer.
after user enter the integer it will assign it to c;
similarly, other data types can also be read..
0
but you shall
to import java.util.Scanner;
if you want to set your variable in GUI and you (for example) want to have an input field "ifield", output field "ofield", button "button" (when you click value of your variable will be show in the ofield), and you have declared variable "variable" you can define actionPerformed method with method like:
value=ifield.getDouble(); //or something else
ofield.setText(value);



