totally lost...

hey y'all!

so, i have this assignment in my computer science I class and i've done a good bit of it! however, i don't know if what i've done is right...and i'm totally lost in how to finish it. i've been working on it for a few days...looking all over the internet...i just don't feel like i know java well enough yet to adapt the info to what i need...any help with this will be much appreciated! y'all have a great day! - andrea

so, here's what i have so far with the assignment instructions there!

/*

This program will contain 10 elements of type integer. Each even numbered element will be equal to the square of a random number between 1 and 10. Each odd numbered element will be equal to the cube of a random number between 1 and 10. Element number zero is considered even for our purposes. This program will do the following:

1. print out the array

2. print the array in reverse order

3. find the maximum number in the array and its location

4. find the minimum number in the array and its location

5. sort the array in descending order

6. find another random number between 1 and 10, determine its square and determine how many times the number occurs in the array (if any).

*/

public class ArrayListTester

{

public static void main (String [] args)

{

int i,j;

int[] data1 = new int[10];

int[] data2 = new int[10];

for (i = 0; i < data1.length; i++)

data1 = i*i;

/* 1. print out the array */

System.out.println("Original array: ");

for(i = 0; i < data2.length; i++)

System.out.print(data1 + " ");

System.out.println("Reverse copy data1 to data2.");

if(data2.length >= data1.length)

for(i = 0, j = data2.length-1; i < data1.length; i++, j--)

data2[j] = data1;

/* 2. print the array in reverse order */

System.out.println("Reversed array: ");

for(i = 0; i < data2.length; i++)

System.out.print(data2 + " ");

}

/* 3. find the maximum number in the array and its location

4. find the minimum number in the array and its location */

public static int max(int[] t)

{

int maximum = t[0];

for (int i = 1; i < t.length; i++)

{

if (t > maximum)

{

maximum = t;

}

}

return maximum;

}

public static int min(int[] t)

{

int minimum = t[0];

for (int i = 1; i > t.length; i++)

{

if (t < minimum)

{

minimum = t;

}

}

return minimum;

}

}

/* 5. sort the array in descending order */

/* 6. find another random number between 1 and 10, determine its square and determine how many times the number occurs in the array (if any). */

ps. none of my formatting stayed like i have it...ugh...sorry!

[2959 byte] By [colesa] at [2007-11-27 2:31:45]
# 1

1) What specific questions/problems do you have?

2) When you post code, please use[code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] on the message entry page. It makes it much easier to read. Please repost with proper formattig.

jverda at 2007-7-12 2:46:53 > top of Java-index,Java Essentials,Java Programming...
# 2

A few quick pointers for ya - please use "code" tags (highlight the code and hit that "code" button above the message text area) when posting code. Please use a more descriptive subject line, and please describe the problem you're having (rather than say "It's not finished and I don't know if what I have is right")

So - try to tell us what your code is supposed to do and what it does (runtime exception? won't compile? unexpected results?)

Good Luck

Lee

tsitha at 2007-7-12 2:46:53 > top of Java-index,Java Essentials,Java Programming...
# 3

Ok because I'm feeling generous today I'm going to get you started.

public class InvolvedExample

{

public static void main(String[] args)

{

// First off let's make an array of ints with 10 elements

int[] intArray = new int[10] ;

int x ; // An int to hold our seed value

Random r = new Random() ;// A randomizer to generate the next random number

StringBuffer buffer = new StringBuffer("intArray[") ;// A place to build a string representation of the array

// Now we'll spin through the array and set its values

for(int i=0; i<intArray.length; i++)

{

x = r.nextInt(10) + 1 ; // Generate the next random number between 1 and 10 inclusive

// Determine if the index of the array is even or odd (not the most graceful code but it works.

if(i % 2 == 0)

{

intArray[i] = (int) Math.pow(x, 2) ;

}

else

{

intArray[i] = (int) Math.pow(x, 3) ;

}

buffer.append(intArray[i]) ;

if(i><(intArray.length-1)){

buffer.append(", ") ;

}

}

buffer.append("]") ;

System.out.println(buffer) ;

}

}

Here's how to build your array (You only need one) The sorting and getting the max and min and finding a number in the array I leave for you to figure out.

Hope this helps,

PS.

puckstopper31a at 2007-7-12 2:46:53 > top of Java-index,Java Essentials,Java Programming...
# 4

sorry. i'm wayyy new to this whole forum thing...i've never done it. i just wanted some feedback on if

what i have is correct and then how to finish my assignment. i can't figure out how to sort in

descending order and i have no idea how to start #6. thanks again for your generous help!!!

/*

This program will contain 10 elements of type integer. Each even numbered element will be equal to

the square of a random number between 1 and 10. Each odd numbered element will be equal to the

cube of a random number between 1 and 10. Element number zero is considered even for our

purposes. This program will do the following:

1. print out the array

2. print the array in reverse order

3. find the maximum number in the array and its location

4. find the minimum number in the array and its location

5. sort the array in descending order

6. find another random number between 1 and 10, determine its square and determine how many times the number occurs in the array (if any).

*/

public class ArrayListTester

{

public static void main (String [] args)

{

int i,j;

int[] data1 = new int[10];

int[] data2 = new int[10];

for (i = 0; i < data1.length; i++)

data1 = i*i;

/* 1. print out the array */

System.out.println("Original array: ");

for(i = 0; i < data2.length; i++)

System.out.print(data1 + " ");

System.out.println("Reverse copy data1 to data2.");

if(data2.length >= data1.length)

for(i = 0, j = data2.length-1; i < data1.length; i++, j--)

data2[j] = data1;

/* 2. print the array in reverse order */

System.out.println("Reversed array: ");

for(i = 0; i < data2.length; i++)

System.out.print(data2 + " ");

}

/* 3. find the maximum number in the array and its location

4. find the minimum number in the array and its location */

public static int max(int[] t)

{

int maximum = t[0];

for (int i = 1; i < t.length; i++)

{

if (t > maximum)

{

maximum = t;

}

}

return maximum;

}

public static int min(int[] t)

{

int minimum = t[0];

for (int i = 1; i > t.length; i++)

{

if (t < minimum)

{

minimum = t;

}

}

return minimum;

}

}

/* 5. sort the array in descending order */

/* 6. find another random number between 1 and 10, determine its square and determine how many times the number occurs in the array (if any). */

colesa at 2007-7-12 2:46:53 > top of Java-index,Java Essentials,Java Programming...
# 5
for sorting in descending order , http://en.wikipedia.org/wiki/Bubble_sort <- read about sorting, then you will be able to write a function ,for generating a random numbers http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.htmlhope this helps
Flummoxeda at 2007-7-12 2:46:53 > top of Java-index,Java Essentials,Java Programming...