Need A Bit Of Help
<div class="IPBDescription">understanding a question =\</div> Alrighty, I'm doing some java programming, very basic stuff as I'm told. No, I dont need help with the programming itself, but in fact with a question.
Here it is;
Write a program that prompts the user for two integers, reads and stores them. The program then swaps the contents of these variables and outputs the new values of firstNum and secondNum.
Thats it. Now forgive me if the answer is blindingly obvious, but, what in the world is it essentially asking me to program?
Dont make any code. I need to learn this for myself. I just need to know, step by step, what I have to do =\
Here it is;
Write a program that prompts the user for two integers, reads and stores them. The program then swaps the contents of these variables and outputs the new values of firstNum and secondNum.
Thats it. Now forgive me if the answer is blindingly obvious, but, what in the world is it essentially asking me to program?
Dont make any code. I need to learn this for myself. I just need to know, step by step, what I have to do =\
Comments
What is your first integer? __
What is your second integer? __
(computer looks at two integers)
(computer writes both on different pieces of paper)
(computer switches the pieces of paper from one hand to another)
(computer reads first paper)
The value is xxx!
int1 = 10
int 2 = 12
make it so
int1 = 12
int2 = 10
OR
you could just ask whoever gave you the question
now im going back to do my java project for uni <!--emo&::nerdy::--><img src='http://www.unknownworlds.com/forums/html//emoticons/nerd.gif' border='0' style='vertical-align:middle' alt='nerd.gif' /><!--endemo-->
Eg.
Num 1 = x
Num 2 = y
System.out.println(Num1); //shows up as x
System.out.println(Num2); //shows up as y
<insert command>
System.out.println(Num1); //now shows up as y
System.out.println(Num2); //now shows up as x
{Edit} Forgot about the ";"'s
int n3 = n1 - n1 + n2
int n4 = n2 - n2 + n1
I'm not happy but it achieves the goal from the end users point of view, cant imagine I'll get good marks for the coding though D:
{
//genio is a cool little class that allows easy access to user inputs and has alot of validation (can enter String when you want an int)
int num1 = Genio.getInteger();
int num2 = Genio.getInteger();
int tempNum;
System.out.println("Number 1 = " + num1);
System.out.println("Number 2 = " + num2);
tempNum = num1;
num1 = num2
num2 = tempNum
System.out.println("Number 1 = " + num1);
System.out.println("Number 2 = " + num2);
}
Edit: In response of your post below, that the beuty of programming you are allowed to use other work as long as
A. you dont hand in 100% code that all others work
B. you keep any documentation about the author in the source
genio was writen by my lecturer to help people learn java, tell your teacher he/she's a bad man
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
int nOne = 43;
int nTwo = 56;
// swap two ints
int nTemp = nOne;
nOne = nTwo;
nTwo = nTemp;
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
just keep in mind what your prof wants you to be doing.
I had one HW that had a piece where we had to take a string of #s and turn it into 1s and 0s (not binary, we had a different table).
There was something specific he wanted us to be working on (I honestly don't remember atm), however I found a nice little piece of Java that would take a string and run a sieries of substitutions on it (you tell it what should become what, and it does it).
I tihnk he wanted us to do it as a for loop, I talked to one of the graders and they basicaly told me to not use the opperator I found b/c that wasn't the point <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html//emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
so yah, keep in mind what he wants you to be ussing.
NOTE: Your assignment could also be done rather simply with a stack, you push on the to ints and then pop em off. They will automaticly revers (its first in last out).