+ 5
It's possible to display directly an array? For example : System.out.print({{3,2} , {5,5} };
java
8 Answers
+ 5
int[] intArr = {1,2,3,4,5,6,7,8,9,10};
System.out.println(intArr[0]);
System.out.println(intArr[1]);
System.out.println(intArr[2]);
System.out.println(intArr[3]);
System.out.println(intArr[4]);
System.out.println(intArr[5]);
System.out.println(intArr[6]);
System.out.println(intArr[7]);
System.out.println(intArr[8]);
System.out.println(intArr[9]);
However, as you can see, if you have a lot of elements then it isn't the best idea to deal with them like that. In that case, you'll use a loop, especially when you've no idea how many elements you'll have. You can simplify the above into just a couple lines:
for(int i = 0; i < intArr.length; ++i){
System.out.println(intArr[i]);
}
^See how that's a lot easier?
https://code.sololearn.com/cEo0zUQSQ4eq/#java
+ 9
Totally misunderstood the question, thanks for the clarification @Netkos Ent :)
+ 5
thinks,
+ 5
@dev, i talk about array not String
+ 4
@Eva No problem. I updated my answer fully, so look at it again for additional information and means of handling this situation. Posted example so you could see it in action on Code Playground.
+ 3
@Dev Definitely bro. I understand how you thought that though, so no worries. lol
0
Try in eclipse
0
use for each loop to display it in a simple different way.
for(int x:intArr){
System.out.print(x);