aspose file tools*
The moose likes Java in General and the fly likes java help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java help" Watch "java help" New topic
Author

java help

richie o donoghue
Greenhorn

Joined: Dec 15, 2001
Posts: 2
hi i was wonderin if any 1 could help me with these problems???Write a program that accepts 3 integer values and outputs them in ascending order.
a) Write a program that outputs the numbers from 30 to 1 (in descending order).

b) Write a program that outputs the numbers from 0 to 20 and their squares, i.e., program output should look like this:

The square of 0 is 0.
The square of 1 is 1.
The square of 2 is 4.
:
:
The square of 20 is 400.

c) Write a program that asks the user for a positive number between 1 and 100 inclusive. If the user enters a valid number, the program then outputs a list of the even numbers between 1 and that number inclusive; if the user enters an invalid number, the program outputs an error message.

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Since these sound like homework problems, I wouldn't be expecting to see any code here. Since you haven't posted code to show that you have at least attempted the problems, I wouldn't expect to get much help until you do.
If you are just completely stuck at where to start, it should be fairly obvious that some kind of flow control is needed here, more specifically a looping construct.
If you want to show some code that you have, it might help us to better address where you are having problems.
Jason
richie o donoghue
Greenhorn

Joined: Dec 15, 2001
Posts: 2
public class WriteValues
{
public static void main (String[] args)
{
int count = 1;
while (count <= 30)<br /> {<br /> System.out.println ("The value of count is now " + count);<br /> count = count + 1;<br /> }<br /> }<br /> }<br /> I DONT KNOW IF THAT WILL WRITE THEM OUT IN DESCENDING ORDER.THIS WAS MY ATTEMPT.<br /> THE FIRST PART TO ENTER 3 INTEGERS I TYPED-public class AscendingOrder<br /> {<br /> public static void main (String[] args)<br /> {<br /> int integer1;<br /> int integer2;<br /> int integer3;<br /> System.out.println ("Please enter an integer and press return");<br /> integer1 = Reader.readInt;<br /> System.out.println ("Please enter a second integer and press return");<br /> integer2 = Reader.readInt;<br /> System.out.println ("Please enter a third integer and press return");<br /> integer3 = Reader.readInt;<br /> <br /> if (integer1 > integer2 > integer3)
System.out.println

AND IM STUCK ON THE SQUARE ROOTS THING???
HELP
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4707
    
    7

>> Originally posted by richie o donoghue:
>> I DONT KNOW IF THAT WILL WRITE THEM OUT IN DESCENDING ORDER.THIS WAS MY ATTEMPT
Well, did you attempt to run the program and see what it printed out? Does it print out 30, 29, 28, ... 1 (correct solution) or 1, 2, 3, ...30 (incorrect solution)?

>> AND IM STUCK ON THE SQUARE ROOTS THING???
HELP
Well, first decide which one you want: do you want the SQUARE of a number (which you can calculate by multiplying the number by itself) or the SQUARE ROOT (in which case, you'd probably want to pass the number to the java.lang.Math.sqrt() method)

Good luck,
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
Biju Philip
Greenhorn

Joined: Nov 03, 2001
Posts: 7
Here's a quick example of your square root task. There are many different variations of this task... you may wish to review iteration in Java (using "for" and "while" loops). Sorry if the formatting is a bit off.
<CODE>
//package name here
/**
* A simple class to create squares of integers.
*/
public class SquareRootGen {
/**
* Creates a new <code>SquareRootGen</code> instance.
*/
public SquareRootGen (){
}

/**
* <code>main</code> method that does the work
*/
public static void main(String args []) {
// create your max integer value
int max = 21;
// create a square root value
int j = 0;
// iterate through starting from zero to one int less than the max value
// it will start from zero and end at 20
for (int i = 0; i < max; i++) {
// assign the value of i times i to j
j = i*i;
// print your statement
System.out.println("The square of " +i +" is " +j +".");
}
}
}// SquareRootGen
</CODE>

[This message has been edited by Biju Philip (edited December 20, 2001).]
[This message has been edited by Biju Philip (edited December 20, 2001).]
[This message has been edited by Biju Philip (edited December 20, 2001).]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Biju
You can fix the formatting of the code you post by enclosing it in UBB code tags. See this page: http://www.javaranch.com/ubb/ubbcode.html
Then you can output things like this:


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Shubhrajit Chatterjee
Ranch Hand

Joined: Aug 23, 2001
Posts: 356

Hi,
I don't mean to be rude but I have a few things to say about homework problems.
These problems are fairly simple and if a student is not able to do it by himself then a lot of help should be around. When I was in college, I would always go to my classmates and ask them for their help. That is I feel a much better way to learn. Next he can consult his mentorsand professors. I think these forums are the last place where he should post and definitely not in an (intermediate java)forum. There is a beginners forum also.
------------------
Shubhrajit


Shubhrajit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java help