-1

I wrote a Java program but I'm getting an error:

ArrayMain.java:13: error: cannot find symbol
            ar[c]=input.nextInt;
                       ^
  symbol:   variable nextInt
  location: variable input of type Scanner

Code:

import java.util.Scanner;
class ArrayMain
{
    public static void main(String[] args)
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter the size:");
        int c=input.nextInt();
        int[] ar=new int[c];
        System.out.println("Enter Element");
        for(int i=0;i<c;i++)
        {
            ar[c]=input.nextInt;
        }

        array(ar,c);
    }
    public static void array(int[] ar,int c);
    {
        System.out.println("Elements in reverse order are");
        for(int i=c;i>0;i--);
        {
            System.out.println(ar[c-1]);
        }
    }
}

How can I fix it?

Pang
  • 9,564
  • 146
  • 81
  • 122
Darshan Jain
  • 31
  • 1
  • 4
  • 1
    Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Andrew Li Mar 05 '17 at 07:20
  • I recommend you to watch java tutorial and view java documentation to be more familiar with syntax of java: https://www.youtube.com/watch?v=WPvGqX-TXP0 – Oghli Mar 05 '17 at 07:35

3 Answers3

0

It should be

 ar[c]=input.nextInt();

and also make sure the method definition is correct

public static void array(int[] ar,int c) {   //notice the removal of semicolon
Naman
  • 27,789
  • 26
  • 218
  • 353
0
ar[c] = input.nextInt;

It's wrong and the correct code is:

ar[c] = input.nextInt(); 
Pang
  • 9,564
  • 146
  • 81
  • 122
sameera lakshitha
  • 1,925
  • 4
  • 21
  • 29
0

you should put the index i instead of c in ar[c] to loop over each input element

System.out.println("Enter Element");
    for(int i=0;i<c;i++)
    {
        ar[i]=input.nextInt();  //not input.nextInt
    }

also method array(int[] ar,int c) have problems it should be:

public static void array(int[] ar,int c) // method decleration shouldn't end with `;`
{
    System.out.println("Elements in reverse order are");
    // for loop mustn't end with ';' for(int i=c;i>0;i--);
    for(int i=c-1;i>=0;i--)  // start at last element index to the first element which index is i=0
    {
        System.out.println(ar[i]);   // loop over each element in reverse order
    }
}
Oghli
  • 2,200
  • 1
  • 15
  • 37