Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: needs help in java programming.

1. ## needs help in java programming.

1. Give a segment of code that will find the position, posLastZero,
of the last zero element among a[0], a[1], ..., a[n-1]. That is,
posLastZero should be the largest integer such that
a[posLastZero] is equal to zero. The value of n is given. If
there is no zero element among a[0], a[1], ..., a[n-1], the code
should set posLastZero equal to a negative one.

Example: n = 7 a[0] = 5
a[1] = 0
a[2] = 7
a[3] = 0
a[4] = 3
a[5] = 0
a[6] = 9

The code should leave posLastZero equal to 5 in this case, because
a[5] is the last zero element among a[0], a[1], ..., a[n-1].
This is only an example; your code must handle any case.

2. Copy the elements a[0], a[1], ..., a[n-1] into the array b[], but
rescale them by dividing them by a[0]. For example, if n=4,
a[0]=1.5, a[1]=9.0, a[2]=3.0, and a[3]=6.0 before the code is
executed, then afterwards the values of the elements of b()
should be b[0]=1.0, b[1]=6.0, b[2]=2.0, and b[3]=4.0.
Each element has been divided by the value, 1.5, of a[0].
This is only an example; of course your code must be general
and must handle any number of elements.

3. Given nA and a[0], a[1], ..., a[nA - 1], with the elements a[j] in
nondecreasing order (a[0] <= a[1] <= ... <= a[nA-1]), give a segment
of code that will "squeeze out the duplicates in-place" and
will set nA equal to the number of unique elements in a.
That is, if nA=5, a[0]=0.0, a[1]=0.0, a[2]=1.2, a[3]=2.3, and a[4]=2.3,
then after execution of the code the contents should be a[0]=0.0,
a[1]=1.2, and a[2]=2.3, and nA=3. The duplicate elements (the second
value of 0.0 and the second value of 2.3) have been eliminated from
the array.
Note:
(The final contents of a[3] and a[4] can be anything.)
This is only an example. Your code must be general and must not
contain any "magic numbers".

4. How should you declare your instance variables in a class?

5. Write a constructor for a class named Dog that has instance variables of
String name, String breed, and int age.

2. ## Re: needs help in java programming.

What questions do you have about your assignment?

3. ## Re: needs help in java programming.

Originally Posted by ryano
needs help in java programming.
When I read this, I can't help but think, "it puts the lotion on its skin, or else it gets the hose..." Useful titles not only help you get help, but they also help us keep from thinking about creepy movies.

4. ## Re: needs help in java programming.

Yeah, I always hate the times I forget what kind of forums i'm on. But luckily the poster reminded me.

People must really think people will do their homework assignments for them... At least make a little effort...

5. ## The Following User Says Thank You to Emperor_Xyn For This Useful Post:

syntax (December 16th, 2011)