Want to create an array with both int and char? Try this following piece of code,This will work for you,However you must keep in mind that An array can contain only a single type of value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); char[] arr = new char[16]; /*taking input from the keyboard*/ for(int i = 0; i < 16; i++) { arr[i] = sc.next().charAt(0); } /*displaying the contents of the array*/ for(int i = 0; i < 16; i++) { System.out.println(arr[i] + ","); } } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.