here we are again another...ugh question..
like the title says after searching an array for the number the program shall try to destroy if it is found...unfortunately (previously when it print the new array it all turns out into zeroes) displays a "not found"...somehow only the first
(previously thing inside the array index 0 is the one can be verified as the number that can be found in my program) but now all existing numbers inside the array can't be found even though it is there..I've tried everything as far as my current knowledge in array goes...help.
import java.util.Scanner;
public class ArrayApp
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int[] DaArray = {34, 234, 456, 21, 5436, 32, 6543, 5, 54, 543, 65, 76, 243 ,678, 23, 67, 14, 547, 65, 452};
int SearchNumbah;
int LengthofArray = DaArray.length;
System.out.print("Please enter a number to be searched: ");
SearchNumbah = console.nextInt();
ArrayDisplay(DaArray);
Search(DaArray, SearchNumbah);
}
public static void ArrayDisplay(int[] TheArray)
{
int LengthofArray2=TheArray.length;
for(int a = 0; a < LengthofArray2; a++)
{
System.out.print(TheArray[a]+" ");
}
System.out.println("");
}
public static void Search(int[] ArrayX, int NumbahX)
{
int LengthofArray2=ArrayX.length;
for(int b = 0; b < LengthofArray2; b++)
{
if(ArrayX==NumbahX)
{
System.out.println("Found "+NumbahX);
}
else
{
System.out.println(NumbahX+" not found");
break;
}
}
}
public static void Destroy(int[] ArrayX, int NumbahX)
{
int LengthofArray3=ArrayX.length;
LengthofArray3 += 3;
for(int d = 0; d < LengthofArray3; d++)
{
if(ArrayX[d]==NumbahX)
{
for(int e = d; e < LengthofArray3; e++)
{
ArrayX[e] = ArrayX[e++];
}
LengthofArray3--;
int[] temp = new int[ArrayX.length];
ArrayDisplay(temp);
}
}
}
}I also tried creating a method to randomize the numbers in each element in the array but it went terribly awry...can anybody tell me how this is done.
Edited by: DaDonYordel on Nov 25, 2007 3:08 AM