Need A Bit Of Help

CronosCronos Join Date: 2002-10-18 Member: 1542Members
<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 =\

Comments

  • TransmissionTransmission Join Date: 2003-03-12 Member: 14456Members
    It wants something like this:

    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!
  • RueRue Join Date: 2002-10-21 Member: 1564Members
    I think its asking you to swap the values in both variables eg
    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-->
  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    Hrmmm, what command would do that? This thing is really starting to annoy me now =\
  • CreepieCreepie Join Date: 2003-02-19 Member: 13734Members
    Command to do what ?
  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    edited March 2004
    Swapping the values such that n1 becomes n2 and vice versa.

    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
  • ThansalThansal The New Scum Join Date: 2002-08-22 Member: 1215Members, Constellation
    yah, cronos got it, exept that you also are taking in the ints, not just declaring them.
  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    I kind of hacked it.

    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:
  • RueRue Join Date: 2002-10-21 Member: 1564Members
    edited March 2004
    public void sampleMethod()
    {
    //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
  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    Thanks but I highly doubt my teacher would appreciate custom addons too much. I'll take a look at that proggy anyway and keep it for later, but until I get through uni it's their way or the fail way =\
  • CreepieCreepie Join Date: 2003-02-19 Member: 13734Members
    I don't do Java. However, the simplest way to swap in C(++) is to use a third variable:

    <!--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-->
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    Most of you guys are making this way way way way WAY too complex for what Chronos needs to do. Go with Creep's answer, its short and to the point. :P
  • ThansalThansal The New Scum Join Date: 2002-08-22 Member: 1215Members, Constellation
    yah, creep hit the way of doing it (it is in truth a VERY simple problem)

    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).
Sign In or Register to comment.