There are some error in lion no 15 .can anyone help me to fix this???
- import java.util.Scanner;
- public class intArray
- {
- public static void main (String [] args)
- {
- final int size =10;
- int [] array = new int [size];
- Scanner input = new Scanner (System.in);
- 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
- }
- printArray (array);
- }
- void printArray (int [] array1) // Dispaly the array
- {
- for (int a=0;a<array1.length;a++)
- {
- System.out.print (array1[a] + " ");
- }
- }
- }
Malaka_1
0
Newbie Poster
Recommended Answers
Jump to PostLook 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.
Jump to Post
int array [a] = input.nextInt();
you don't need to declare the separate elements. replace the above by:
array[a] = input.nextInt();
Jump to PostAhh, 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!
All 9 Replies
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
stultuske
1,116
Posting Maven
Featured Poster
Malaka_1
commented:
array[a] = input.nextInt(); when i use this, it give me more erros
+0
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
Malaka_1
0
Newbie Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
Malaka_1
0
Newbie Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
stultuske
1,116
Posting Maven
Featured Poster
Malaka_1
0
Newbie Poster
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.