+ 2
Array
Can you tell me the error in the following code I cannot sort it out... https://sololearn.com/compiler-playground/ctzKO4I1w6lq/?ref=app
10 ответов
+ 5
import java.util.Arrays;
public class Program {
public static void main(String[] args) {
int[] marks = new int[3];
marks[0] = 89;
marks[1] = 90;
marks[2] = 78;
// Sorting the array
Arrays.sort(marks);
// Printing the second element of the sorted array
System.out.println(marks[1]);
}
}
this will be its correct code
+ 1
an array can be declared like this:
int [] marks = new int[3];
if you want to print the first element, remove the "" from the output
+ 1
I haven't code for Java for a while and forget how to create array.
After reviewing my notes, I also found another you made.
Instead of:
int marks[0] = 89;
It should be:
marks[0] = 89;
You already declared an integer array, so you don't need to assign an array member and state that it is an integer again.
+ 1
Okk Thanku now its done I will try to be more clear with these syntax
0
Lisa its still not done
0
carefully compare my example and your line 7. which part is missing in your code?
0
Aditi Chand
look at Lisa's reply carefully.
this
⬇️
int[] marks = new int[3];
your code:
int marks = new int[3];
type int is not the same as type int[]. one is integer, the other is integer array
0
Can you just do it and share it please
0
don't be lazy... if you can't see the mistake now, you should redo the lesson. Don't build on shaky foundations.
0
Wong Hei Ming those new errors must have been added afterwards. They were not there when I looked at the code.
Now there are more mistakes in the code.
Please redo the lesson. The basics are very important. Do not guess the correct syntax.