|
|
![]() |
|
|
Top | #1 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
Write a Java program with the following methods: Named ‘first’ that will input a number and return it. Named ‘second’ that will input a number and return it. Named ‘small’ that will find the smaller of the two numbers and return it. This is what I have so far... Code:
import cs1.Keyboard; //this is used for Keyboard inputs
public class BigSmall
{
public static void main (String[] args)
{int num1, num2;
System.out.println ("Enter the first number ");
num1 = Keyboard.readInt();
System.out.println ("Enter the second number ");
num2 = Keyboard.readInt();
static int first (int num1)
{int a;
a = num1;
return a;
}
static int second (int num2)
{int b;
b = num2;
return b;
}
static int smaller (int a, int b)
{
if a < b;
return a;
}
}
}
|
|
|
|
|
|
Top | #2 |
|
NTFS Guru
Joined: January 2002
Location: Sweden
Posts: 4,006
Reputation: 890
Power: 171 |
Yes...? What's the question?
And what are the first two methods for? They do exactly nothing... Looking again... Why are the methods inside main? Does that even compile? |
|
|
|
|
|
Top | #3 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
this is what I need to do... (it was the first thing in the post)
|
|
|
|
|
|
Top | #4 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 213 |
I dont really know how your cs1.Keyboard import object works so I wrote it up how would have done
PHP Code:
|
|
|
|
|
|
Top | #5 |
|
F@H - Is it in you?
Joined: April 2002
Location: Between Austin and Tampa
Posts: 14,880
Reputation: 4110
Power: 309 |
name your int's as whatever they are... keep in mind I am just giving you a basic gist of the coding..
its also a little simpler than geffy's ![]() Code:
import cs1.Keyboard;
public class SmallNumber
{
//enter b.s. explanation here :)
//
public static void main (String[] args)
{
//declare ints
int first, second, small = 0;
System.out.println ("Enter 2 integers: ");
first = Keyboard.readInt();
second = Keyboard.readInt();
if (first < second)
small = first;
else
small = second;
System.out.println ("The smallest value is : " + small);
}
}
|
|
|
|
|
|
Top | #6 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
you guys are the best. I needed it 2 hours ago but the good thing is no one in class even started it. I am now hoping I can get some extra credit with it. WAHOO!?!
|
|
|
|
|
|
Top | #7 |
|
F@H - Is it in you?
Joined: April 2002
Location: Between Austin and Tampa
Posts: 14,880
Reputation: 4110
Power: 309 |
yeehah... go us...
@ this rate pk's degree will belong to us
|
|
|
|
|
|
Top | #8 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
well I am changing my major so unless you can do painting drawing and digital design, the degree will be mine... muhahahaha
|
|
|
|
|
|
Top | #9 |
|
F@H - Is it in you?
Joined: April 2002
Location: Between Austin and Tampa
Posts: 14,880
Reputation: 4110
Power: 309 |
![]() you ungrateful @#$#@$!@# !!!!1
|
|
|
|
|
|
Top | #10 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
yeah well my 2 year degree is now gonna take almost 3 years now. I am going into graphics and web design.
|
|
|
|
|
|
Top | #11 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 213 |
graphics and web design is more fun than Java I feel, I love doing web design as people can more easily appreciate the asthetic beauty in a nicely designed and usable website, but not many people can see beauty in Java code
|
|
|
|
|
|
Top | #12 |
|
Zug Zug
Joined: April 2002
Location: Ice Crown Citadel
Posts: 3,858
Reputation: 490
Power: 162 |
I used to do art work for a lot of years but gave it up when I found computers. It wasnt till recently I got a grip on PS7 and other graphics programs ... much more fun than Java and easier for me.
|
|
|
|
|
|
Top | #13 |
|
*
Joined: December 2001
Location: USA
Posts: 6,490
Reputation: 2808
Power: 217 |
Hrm, i like Geffy's better, it at least compiles and works with gjc, i dun know what cs1.importkeyboard.crap is.
|
|
|
|
|
|
Top | #14 |
|
*
Joined: December 2001
Location: USA
Posts: 6,490
Reputation: 2808
Power: 217 |
PHP Code:
|
|
|
|
|
|
Top | #15 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 213 |
yeah, bit neater that, the smaller() call looks slightly more confusing I can picture my Java Lecturer saying, but it does all compile and run on java sdk 1.4.2
|
|
|
|
|
|
Top | #16 |
|
*
Joined: December 2001
Location: USA
Posts: 6,490
Reputation: 2808
Power: 217 |
Doesnt look confusing at all. But then again i am used to nesting a lot of calls in one.
|
|
|
|
|
|
Top | #17 |
|
F@H - Is it in you?
Joined: April 2002
Location: Between Austin and Tampa
Posts: 14,880
Reputation: 4110
Power: 309 |
what aboot mine?
it does the task w/o all teh crap...
|
|
|
|
|
|
Top | #18 |
|
*
Joined: December 2001
Location: USA
Posts: 6,490
Reputation: 2808
Power: 217 |
Geffy's is strict java, as in it will compile on any Java, yours uses some special keyboard library.
|
|
|
|
|
|
Top | #19 |
|
F@H - Is it in you?
Joined: April 2002
Location: Between Austin and Tampa
Posts: 14,880
Reputation: 4110
Power: 309 |
Originally Posted by X-Istence
I used it since obviously pk is using it
|
|
|
|
|
|
Top | #20 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 213 |
I just dunno how that cs1.keyboard thinger works or how the code is setup so I tend to use my own, I have been thinking of rolling my own Keyboard, and so on classes though
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Overriding Methods in Visual Studio 2005 | Complete | Web Design & Coding | 0 | October 10th, 2007 8:32pm |
| Methods before Members or Members before Methods? | Complete | Web Design & Coding | 2 | September 19th, 2007 11:15am |
| methods for WBXML decoding | sachinjain_30 | Portable Devices & Gadgets | 0 | October 5th, 2006 5:17pm |
| Backup methods? | jkoXP | Windows Desktop Systems | 5 | September 16th, 2003 11:51pm |
| Other Methods With Ramdisk!?? | Hercules | Windows Desktop Systems | 2 | April 14th, 2002 12:13am |