How will the following program be cpp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How will the following program be cpp

public class Program { public static void main(String[] args) { String[] array = new String[10]; array[0] = "1"; array[1] = "2"; array[2] = "3"; array[3] = "4"; for(String s : array) { if(s==null) { System.out.println("Empty"); } else { System.out.println(s); } } } }

5th Apr 2018, 11:07 PM
Farrukh Yuldoshev
Farrukh Yuldoshev - avatar
2 Answers
+ 4
James you used integers not strings or character arrays so I don't think your code is a match. Farrux Yo'ldoshev there are two choices. - An array of the string class, which has "" for the unassigned strings and has no way to detect the difference between assigned empty strings & unassigned strings. - An array of pointers to the string class, which lets you know when the strings been assigned. I coded this method as I believe it is a closer match to the Java: https://code.sololearn.com/c09veG82pwAr
6th Apr 2018, 2:45 AM
John Wells
John Wells - avatar
0
thanks very much
7th Apr 2018, 12:48 PM
Farrukh Yuldoshev
Farrukh Yuldoshev - avatar