Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Dynamic-variable-names/Java/dynamic-variable-names.java
Normal file
14
Task/Dynamic-variable-names/Java/dynamic-variable-names.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
public static void main(String... args){
|
||||
HashMap<String, Integer> vars = new HashMap<String, Integer>();
|
||||
//The variable name is stored as the String. The var type of the variable can be
|
||||
//changed by changing the second data type mentiones. However, it must be an object
|
||||
//or a wrapper class.
|
||||
vars.put("Variable name", 3); //declaration of variables
|
||||
vars.put("Next variable name", 5);
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String str = sc.next();
|
||||
vars.put(str, sc.nextInt()); //accpeting name and value from user
|
||||
|
||||
System.out.println(vars.get("Variable name")); //printing of values
|
||||
System.out.println(vars.get(str));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue