1

I want to make an array that its length customized. Here is the code :

import java.util.Scanner;

public class ArrayInt
{
    static Scanner input = new Scanner(System.in);  
    public static void main(String[] args)
    {
        int Arraynya[];

        System.out.print("Input panjang Array: ");
        int inputan = input.nextInt();

        Arraynya = new int[inputan];

        Arraynya data[] = new Arraynya[inputan];

        for(int i=0;i<Arraynya.length;i++)
        {
            System.out.println("Input data ke "+(i+1)+" : ");
            int isi = input.nextInt();

        }
        Arraynya[inputan] = isi;    
        System.out.println("Arraymu :"+Arraynya[inputan]);

    }
}

But it show errors :

ArrayInt.java:15: error: cannot find symbol Arraynya data[] = new Arraynya[inputan]; symbol: class Arraynya location: class ArrayInt

ArrayInt.java:15: error: cannot find symbol Arraynya data[] = new Arraynya[inputan]; symbol: class Arraynya location: class ArrayInt

ArrayInt.java:23: error: cannot find symbol Arraynya[inputan] = isi; symbol: variable isi location: class ArrayInt

3 errors

How can i input customized Array and show it properly? Should i use ArrayList ?

ochabi121
  • 11
  • 1
  • I don't really get what you're trying to do when you write `Arraynya data[] = new Arraynya[inputan];`. That doesn't make sense from a syntax point of view and the `Arraynya` array variable already seems to be the thing you want. – Bernhard Barker Mar 25 '18 at 08:59
  • Do you have class `Arraynya`? or is it a variable? – Guy Mar 25 '18 at 09:01
  • @Guy : Arraynya is the name of Array – ochabi121 Mar 25 '18 at 09:06
  • You should really use `int[] arraynya`, not `int Arraynya[]`. Having the array declaration after the variable name is discouraged, and variables names should start with lowercase. – Mark Rotteveel Mar 25 '18 at 09:52

1 Answers1

0

ArrayInt.java:15: error: cannot find symbol Arraynya data[] = new Arraynya[inputan]; symbol: class Arraynya location: class ArrayInt

Arraynya data[] = new Arraynya[inputan]; it stores objects of Arraynya I dont understand why you have used this statemnt but it creates an array type of Arraynya.. with the variable name data with the size of inputan... it stores objects of Arraynya.. as there is no class called Arranynya you are getting an error "cannot find symbol"

int Arraynya[] = new int[]; // it stores integers