+ 1
Could someone helps me?😂 I got some trouble in java array.Please!🙏
public class Java{ public static void main(String[] args) { int[] a=new int[5]; for(int i=0; i<a.length;i++) a[i]=i+1; System.out.println("a[" +i+"]" + "="+a[i]); } }
7 Respuestas
+ 5
Hi, sorry for the delay, I was knocked out for hours, well, I have re-test the code, I am guessing you might have invalid character copied along with the code probably, that might be the cause for compilation error. Can you run this again just to check:
public class Program
{
public static void main(String[] args) {
int[] a=new int[5];
for(int i=0; i<a.length;i++){
a[i]=i+1;
System.out.println("a[" + i + "]=" + a[i]);
}
}
}
You can find me in SoloLearn Discord server, there are more Java knowledgeable people there too, see this thread for more info about Discord:
https://www.sololearn.com/Discuss/689391/?ref=app
Server invite link:
https://discord.gg/MEjFNcC
+ 7
You forgot to add curly braces to wrap the for loop body, remember when there are more than one instructions line in a block you need to wrap them in curly braces : )
public class Java{
public static void main(String[] args) {
int[] a=new int[5];
for(int i=0; i<a.length;i++){
a[i]=i+1;
System.out.println("a[" +i+"]" + "="+a[i]);
}
}
}
Hth, cmiiw
+ 4
Oh, sorry about that Hunt , can you tell me if you get any error message running the code? I tried to run that code in Code Playground and got result as follows:
a[0]=1
a[1]=2
a[2]=3
a[3]=4
a[4]=5
Maybe we'll work something out, come and talk to me : )
+ 1
Hi,nice to meet you.
But it still did not work😂
+ 1
Yeah i follow your way to do it,but the output of my program always show "Compilation error". This is my program👇👇👇👇
public class Program
{
public static void main(String[] args) {
int[] a=new int[5];
for(int i=0; i<a.length;i++){
a[i]=i+1;
System.out.println("a[" +i+"]" + "="+a[i]);
}
}
}
By the way,how can i talk to you personnally😂
+ 1
Thank you,your program works!
+ 1
Ok,i will find you guy!