Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bastet Massri   on Apr 22 In Java Category.

  
Question Answered By: Baylen Smith   on Apr 22

can someone proofread what's wrong with this, and tell me please??!


public class Arrays
{

public static void main(String[] args)
{
int []z = {-1, -5, -2, 5, 3, 4, 9, 7, 8, -9}; //listing
initializing
int []even = new int[10];
int []nonpositive = new int[10];
int []odd = new int[10];

even(z, even);
odd(z, odd);
nonpositive(z, nonpositive);

int SizeEven;
int SizeNonpositive;
int SizeOdd;

SizeEven = even(z,even);
DisplayEven(even, SizeEven);

SizeOdd = odd(z,odd);
DisplayOdd(odd,SizeOdd);

SizeNonpositive = nonpositive(z,nonpositive);
DisplayNonpositive(nonpositive, SizeNonpositive);
}

public static int even (int []z, int[]even) //Set codes for even
arrays
{
int q;
int r = 0;
for(q = 0; q < z.length; q++){
if (z[q]%2== 0){
even[r]=z[q];
r++;
}
}
return r;
}

public static void DisplayEven (int []even, int[]
SizeEven) //Display even numbers
{
int i;
for (i = 0; i < SizeEven; i++){
System.out.println (even[i] + " " );
}

System.out.println();
}


public static int odd (int []z, int[]odd) //Set codes for odd arrays
{
int s;
int t = 0;

for(s = 0; s < z.length; s++){
if (z[s]%2!= 0){
odd[t]=z[s];
t++;
}
}
return t;
}

public static void DisplayOdd (int []odd, int[]SizeOdd) //Display
odd numbers
{
int i;
for (i = 0; i < SizeOdd; i++){
System.out.println (odd[i] + " " );
}
System.out.println();
}

public static int nonpositive (int []z, int[]nonpositive) //Set
codes for negative arrays
{
int s;
int t = 0;

for (s = 0; s < z.length; s++){
if (z[s] < 0){
nonpositive[t] =z[s];
t++;
}
}
return t;
}

public static void DisplayNonpositive (int[]nonpositive, int[]
SizeNonpositive) //Display negative numbers
{
int i;
for (i = 0; i < SizeNonpositive; i++){
System.out.println (nonpositive[i] + " " );
}
System.out.println();
}
}


Share: