0

how to input a variable in java

19th Oct 2016, 10:05 AM
Dheeraj
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..
19th Oct 2016, 10:16 AM
Akash Middinti
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);
19th Oct 2016, 9:14 PM
Maciej GĂłraj
Maciej GĂłraj - avatar