I am learning array concept in java. Please help to resolve the below problem.
Using the below code, i was able to print only the entered values and it's not storing the previously entered values.I want to use Array to add elements and print the same in my problem statement. I should not use ArrayList
Main Class:
System.out.println("Enter the array value");
int value = scan.nextInt();
scan.nextLine();
arrayobj.add(value);
Array Class:
Integer array[] = new Integer[100];
public void add(Integer value){
for(int i=0;i<1;i++)
{
array[i] = value;
i++;
}
System.out.println("The values are");
for(Integer a : array)
{
if(a!=null)
{
System.out.println(a);
}
}
}
Sample Input and Output :
Enter your choice
1.Add
2.Remove
3.Search
1
Enter the array value
1
The values are
1
Do you want to continue[Yes/No]
Yes
Enter your choice
1.Add
2.Remove
3.Search
1
Enter the array value
2
The values are
1
2