Oh great Java Programmers,
I am so clueless on my homework assignments. I thought I might be on the right track but alas, I really have no idea. Perhaps if one of you fantastic people will help me with this problem, I might be able to figure out the second??
Here's the assignment:
Write a program that initializes an array with ten random integers and then prints four lines of output, containing:
1) Every element at an even index. 2) Every even element. 3) All elements in reverse order. 4) Only the first and last element.
Here is the code I have so far: (Please note that I don't really get the return statements of methods and how I would pull all of this together to get my final 4 lines of print)
Thank you in advance for your help!!!Code:import java.util.Arrays;
import java.util.Scanner;
public class FourLines
{
public static void main(String[] args)
{
}
/** Read a series of inputs.
@return an array continaing the numbers.
*/
public static double[] readInputs()
{
final int LENGTH = 500;
double[] data = new double[LENGTH];
int currentSize = 0;
System.out.println("Please enter values. Enter Q to quit:");
Scanner in = new Scanner(System.in);
while (in.hasNextDouble())
{
if (currentSize >= data.length)
{
data = Arrays.copyOf(data, 2 * data.length);
}
data[currentSize] = in.nextDouble();
currentSize++;
}
return Arrays.copyOf(data, currentSize);
}
public static double[] evenIndex(double data)
{
for (int i = 0; i <= data.length; i = i + 2)
{
System.out.println(i);
i++;
}
}
public static double[] printEven(double data)
{
for (int i = 0; i <= data.length; i++)
if (data / 2 == 0)
{
System.out.println(data);
i++;
}
else
{
i++;
}
}
public static double[] printReverse(a[])
{
for (int i = data.length - 1; i >= 0; i--)
{
System.out.println(data[i] + " ");
}
System.out.println();
}
}
~Jaime

