Problem in code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem in code

I found this code on the internet and I was wondering why its not possible to simply modify array like: "String[] fruitOptions = {"Apple", "Apricot", "Banana" into for example:" int[] fruitOptions ={1,2,3}" How I would have to change this code to use integers instead of strings? link: https://www.thoughtco.com/example-java-code-for-building-a-simple-gui-application-2034066

28th Mar 2017, 9:17 PM
lukas
lukas - avatar
7 Answers
+ 1
public class Program { public static void main(String[] args) { int[] fruitOptions ={1,2,3}; System.out.print(fruitOptions[0]); } } it does work. Your problem might be related to the usage perhaps that combo box or whatever can't use an array of integers
28th Mar 2017, 9:22 PM
LordHill
LordHill - avatar
0
in which language?
28th Mar 2017, 9:20 PM
ZeroOne;
ZeroOne; - avatar
0
java
28th Mar 2017, 9:20 PM
lukas
lukas - avatar
0
int[] fruitOption={1,2,3}
28th Mar 2017, 9:24 PM
ZeroOne;
ZeroOne; - avatar
0
sorry i just typed it in here incorectly code is not working with or without the space doesnt matter
28th Mar 2017, 9:26 PM
lukas
lukas - avatar
0
you end the line with ;
28th Mar 2017, 9:27 PM
LordHill
LordHill - avatar
0
whole code is the same as in the link, all ; are on its place only thing changed is String for int and values in array
28th Mar 2017, 9:30 PM
lukas
lukas - avatar