Questions about Arrays: Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Questions about Arrays: Java

I have some questions about arrays in Java. (One of them is actually related more to variables on their own rather than arrays, actually.) 1. Can you convert a variable into another variable? Such as a character into an integer? And if yes, how? 2. Can you get user input for an array? Basically, if someone wants to put how many integers they want, is there a way to simply store them into a scanner array, so that we dont need to declare all variables for all possible numbers? And if yes, how? Thank you for underatanding.

13th Nov 2021, 9:45 AM
Billy Beagle
1 Answer
+ 2
Billy Beagle ASCII value of a character is an integer. You can assign character to int data type but when you print that, ASCII value will be print. int c = 'c'; System.out.println (c); //print 99 Using loop you can get user input and store in an array so no need to define variable for every input. Remember an array can contain only similar type of data so when you try to store another data type, you will get error. And also you can not change length of an array so array list would be best option to store dynamic data.
13th Nov 2021, 10:03 AM
A͢J
A͢J - avatar