java - Cannot find symbol: method add -
why receiving following error: cannot find symbol: method add
? code:
import java.util.* public class arraylist { // instance variables - replace example below own public void processinput(string s) { int[] = { 34, 25, 16, 98, 77, 101, 24 }; arraylist b = new arraylist(); (int = 0; < a.length; i++) { int d = a[i]; if (d % 2 > 0) { b.add(new integer(d)); } } (int = 0; < b.size(); i++) { system.out.print(b.get(i) + " "); } (int = a.length - 1; >= 0; i--) { system.out.print(a[i] + " "); } } }
how can resolve error?
reading question again, assume missing
import java.util.*;
at start of class. way getting error. btw should getting error "cannot resolve symbol arraylist" tells problem is.
change last loop
for(int = a.length-1; >= 0; i--) {
with experience able read error messages , understand mean. in case
exception in thread "main" java.lang.arrayindexoutofboundsexception: 7 @ main.main(main.java:33)
on line 33, (or ever in code) tried accessed index beyond end of array. last element of array a
a.length-1
because first element 0
it important read error message because best clue problem , how fix it.
when post question should post error getting.
Comments
Post a Comment