D
D
Dmitry Belman2016-03-19 17:49:07
Java
Dmitry Belman, 2016-03-19 17:49:07

What is the reason for Array required but int found?

Just in case, I attached the entire code so that it was definitely not taken out of context. The get method returns the i-th element from the array, which is written in the list a under the number k. Return in the body of the get method throws this error. I understand that something is wrong, but I can’t specifically identify the root of the error. I would be
grateful for any advice or hint .

public class Main implements Cloneable {
     
    public static void main(String[] args){
    List<int[]> a = new ArrayList<int[]>();
    Scanner reader = new Scanner(System.in); 
     
int n;
    for( ; ; ) {
        n = reader.nextInt(); 
        if(n<100000) break;            
    }      
int[] a0 = new int[n];
    for (int i = 0; i < n; i++)
        a0[i] = reader.nextInt();
    a.add(a0);
int m;
    for( ; ; ) {
        m = reader.nextInt(); 
        if(m<100000) break;            
    } 
          
        for (int i = 0; i < m+1; i++){
        String request = reader.nextLine();
          
    if (request=="create")  {
       
            int version = reader.nextInt();
            int position = reader.nextInt(); 
            int symbol = reader.nextInt();
            
          create(a, position, version, symbol);
            
    } else
    if (request=="get")     {
        
            int version = reader.nextInt();
            int position = reader.nextInt();
           
             System.out.println(get(a, position, version));
            
    }  
        }   
    }
    
   public static void create(List<int[]> a, int position, int version, int symbol){
    
          a.add((a.get(version)).clone());
          int last=a.size();
          a.get(last)[position]=symbol;
          
      }
  
    public static int get(List<int[]> a, int position, int version){
   
          return a.get((version)[position]);
          }
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-19
@all_bcs_of_you

return a.get((version)[position]);there is a mistake, the brackets are placed incorrectly. That's right:
return a.get(version)[position];get returns an array from which [] is taken int.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question