the program should be able to display array (11 22 33 44 55 66 77 88 99 00).
then will ask user to input a number that is (only) in the array displayed.
then display the new array. sample: input = 44, new array should be 11 22 33 55 66 77 88 99 00, '44' is removed.
here's my code so far
import java.util.Scanner;
class ArrayApp
{
public static void main(String[] args)
{
int[] numbers = {11, 22, 33, 44, 55, 66, 77, 88, 99, 00};
Scanner sc = new Scanner(System.in);
System.out.print("Enter a value to search: ");
int val = sc.nextInt();
// Search the array for val
boolean found = false;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] == val) {
System.out.println(val + " is found at index " + i);
found = true;
break;
}
}
if (!found)
System.out.println(val + " is NOT found.");
System.out.println();
int[] newAr = new int[numbers.length];
for (int i = 0; i < numbers.length; i++)
newAr[i] = numbers[i];
System.out.print("newAr contains: ");
for (int i = 0; i < newAr.length; i++)
System.out.print(newAr[i] + " ");
System.out.println();
}
}