can someone help me?

T

tequila

can someone help me with this problem? at least advice on how to start
it. thanks

Write a Java program that, other than an array and its size, uses no
local (other than parameters) or global memory to return the nth
element of a list . No assignment operation should appear in this
program. Your solution should expand the following code:


class nArray {
//only static initial state is allowed
static final int array[ ] = {7,3,16,41,-3,12,8,8,-1,-53 };
static final int size = 10;

//put your public static method for finding the nth element of the
array here..



static public void main(String [] argv) {
System.out.printf((" The element at position is %d is
%d%n",
4 ,
nth(array,size,4));
}

}
 
L

Leon

Write a Java program that, other than an array and its size, uses no
local (other than parameters) or global memory to return the nth
element of a list . No assignment operation should appear in this
program. Your solution should expand the following code:

What kind of element, an Object or an int? What is wrong with "return
array[position];" or return array[position + 1];" (depending on how you count) ?
class nArray {
//only static initial state is allowed
static final int array[ ] = {7,3,16,41,-3,12,8,8,-1,-53 };
static final int size = 10;

size is not needed, unless you wish to be able to declare a larger array than
size. array.length is the attribute you need.
//put your public static method for finding the nth element of the
array here..



static public void main(String [] argv) {
System.out.printf((" The element at position is %d is
%d%n",
4 ,
nth(array,size,4));
}

- Normally, Java's System.out does not have printf.
- Since array is an attribute of nArray, why would you put it in the parameter
list?
 
?

.

can someone help me with this problem? at least advice on how to start
it. thanks

Write a Java program that, other than an array and its size, uses no
local (other than parameters) or global memory to return the nth
element of a list . No assignment operation should appear in this
program. Your solution should expand the following code:

class nArray {
//only static initial state is allowed
static final int array[ ] = {7,3,16,41,-3,12,8,8,-1,-53 };
static final int size = 10;

//put your public static method for finding the nth element of the
array here..

First step, create the signature for the method. For example, the
signature for the main method is:

static public void main(String [] argv)

Look at the main method for clues to the signature for your method. Second
step, fill in the body of the method. What do they want the method to do?
What information do you have available? The fact that they are limited you
to the input given means you really have a limited solution. You shouldn't
need any extra variables. There is a specific solution they are looking
for.
static public void main(String [] argv) {
System.out.printf("The element at position is %d is %d%n",
4, nth(array,size,4));
}

}

This is a REALLY simple exercise. Don't over think it.
 
S

Stefan Schulz

can someone help me with this problem? at least advice on how to start
it. thanks

Certainly. What do you pay me?

Please put at least a bit of effort into solving the problem yourself.
Also note that this sort of questions belongs to comp.lang.java.help
 
B

Brendan

tequila said:
can someone help me with this problem? at least advice on how to start
it. thanks

Write a Java program that, other than an array and its size, uses no
local (other than parameters) or global memory to return the nth
element of a list . No assignment operation should appear in this
program. Your solution should expand the following code:


class nArray {
//only static initial state is allowed
static final int array[ ] = {7,3,16,41,-3,12,8,8,-1,-53 };
static final int size = 10;

//put your public static method for finding the nth element of the
array here..



static public void main(String [] argv) {
System.out.printf((" The element at position is %d is
%d%n",
4 ,
nth(array,size,4));
}

}
class nArray {
//only static initial state is allowed
static final int array[ ] = {7,3,16,41,-3,12,8,8,-1,-53 };
static final int size = 10;

//put your public static method for finding the nth element of thearray
here..
int nth(int[] ary, int size,int n)
{
return ary[n];
}

static public void main(String [] argv) {
System.out.printf((" The element at position is %d is%d%n", 4 ,
nth(array,size,4));
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top