1. There are some error in lion no 15 .can anyone help me to fix this???

    1. import java.util.Scanner;
    2. public class intArray
    3. {
    4. public static void main (String [] args)
    5. {
    6. final int size =10;
    7. int [] array = new int [size];
    8. Scanner input = new Scanner (System.in);
    9. for (int a=0 ; a<size; a++) //data entering
    10. {
    11. System.out.println ("Enter the " + a+1 + " Element :");
    12. int array [a] = input.nextInt();//somthing is wrong in this line
    13. }
    14. printArray (array);
    15. }
    16. void printArray (int [] array1) // Dispaly the array
    17. {
    18. for (int a=0;a<array1.length;a++)
    19. {
    20. System.out.print (array1[a] + " ");
    21. }
    22. }
    23. }

Look at the positioning of you brackets. Is that right? I don't think so. For a comparison, look at the positioning of the brackets used in the declaration of the main method.

int array [a] = input.nextInt();

you don't need to declare the separate elements. replace the above by:

array[a] = input.nextInt();

commented: array[a] = input.nextInt(); when i use this, it give me more erros +0

Ahh, yes, didn't REALLY look, that is not an instantiation of the array, but a defining of one of the elements, DOH!

Dang unformatted code blurb!

array[a] = input.nextInt();

when i use this, it give me more erros

WHAT errors!? The problem description "doesn't work", doesn't help.

Edit: Although, if I remember right, you MAY want to do nextLine() immediately after the line using nextInt() or your Scanner will still be stuck on the previous line of input, and attempt to read the newline as the int in the next nextInt() call.

for (int a=0 ; a<size; a++) //data entering
{
System.out.println ("Enter the " + a+1 + " Element :");
int array [a] = input.nextInt();//somthing is wrong in this line
}

when i try to compile this program it shows a error in

int array [a] = input.nextInt();//somthing is wrong in this line

this line.

i want to know what is the error in this line

Well, WHAT exception is it throwing, or what compiler message is resulting. Both java (if it is runtime) and javac (if it is compiletime) will tell you EXACTLY what the problem is (it can sometimes be a bit difficult to interpret, though) but we CANNOT help you unless you tell us WHAT THOSE MESSAGES ARE. Again, the problem description "doesn't work", doesn't help.

AND, you have ALREADY been told NOT to use "int" on that line.

actually, Malaka, it won't throw any exceptions/cause errors.
your remaining problem, is that you are calling the non-static method printArray in a static context.

so: declare that method as static, and remove the int from the line where you enter information in the array, as mentioned before.

yes yes
now its ok
i remove first" int " in "int array [a] = input.nextInt();"
and

i change "void printArray (int [] array1) // Dispaly the array" to "public Static void printArray (int [] array1) "

now my program is working

thank you all again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.