Help me, my code is not producing any output. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Help me, my code is not producing any output.

Is this some kind of bug in sololearn? The Java compiler is not producing any output. It often does this, but if I do an edit to the code, it works. Not for this code, it's not working :( Anyone know what's going on? https://code.sololearn.com/cg3sYJShwC63/?ref=app

26th Aug 2021, 5:52 AM
Rishi
Rishi - avatar
6 ответов
+ 4
End the comment with */.
26th Aug 2021, 6:04 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
recommend use List<String> al = new ArrayList<>(); instead of ArrayList al = new ArrayList(); else sololearn will through an error Note: ./Playground/ArrayListDemo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
26th Aug 2021, 6:29 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
import java.util.*; public class ArrayListDemo { public static void main(String args[]) { List<String> al = new ArrayList<>(); System.out.println("Initial size of al: "+ al.size()/2); al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add(1, "A2"); //al.addAll(al); System.out.println("Size of al after additions: " + al.size()); System.out.println("Contents of al: " + al); al.remove("F"); al.remove(2); System.out.println("Size of al after additions: " + al.size()); System.out.println("Contents of al: " + al); // al.clear(); } }
26th Aug 2021, 6:27 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
- store different types is possible with this trick, but I'm not recommended it because it is confused ArrayList<Object> arr = new ArrayList<>(); arr.add("String"); arr.add(20); arr.add(true); - sometimes SoloLearn returns 'no output' instead there is some stupid error like } missing, yes it is bug
26th Aug 2021, 2:34 PM
zemiak
0
CarrieForle ooh wow I feel dumb :-/ I have another clarification to be made. I'm able to add elements of different data types to my ArrayList. How is that working?
26th Aug 2021, 6:08 AM
Rishi
Rishi - avatar
0
HrCoder I'm able to add data of different data types in my ArrayList, what about that? Is it usable like that or, it's not safe or something?
26th Aug 2021, 8:56 AM
Rishi
Rishi - avatar