Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Java, programming
BloodReign
post Feb 19 2012, 09:32 AM
Post #1
Lurker
Serf




Hey guys, I've just started a dual cert4 in programming and networking and I've been given some java code to mod changing variables from numbers to names.
Here is what I came up with but it doesn't work could someone give me a hand with it please..

public class Swap{

public static void main(String[]args){
int nameOne = Susan, nameTwo = Peter, temp;

//Swap two variables:
temp = nameOne;
nameOne = nameTwo;
nameTwo = temp;
System.out.println("nameOne= " + nameOne + "; nameTwo=" + nameTwo);
}
}

Go to the top of the page
 
+Quote Post
Charcoal
post Feb 19 2012, 09:56 AM
Post #2
Hero
Guru




First off you're declaring nameOne, nameTwo and temp as integers.
Integers can only hold whole numbers.
But I'm guessing you want to have the variables hold the names "Susan" and "Peter".

To do that you need to change the int to String. This changes what time of data the variable holds.
You'll also need to surround the "Susan" and "Peter" in double quotes, just like you've done down the bottom in the system.out.println().

This post has been edited by Charcoal: Feb 19 2012, 09:57 AM


--------------------
I<3G

Kikz: Good for you, your sig says something. whoop-de-do dude.
Go to the top of the page
 
+Quote Post
BloodReign
post Feb 19 2012, 10:44 AM
Post #3
Lurker
Serf




QUOTE (Charcoal @ Feb 19 2012, 10:56 AM) *
First off you're declaring nameOne, nameTwo and temp as integers.
Integers can only hold whole numbers.
But I'm guessing you want to have the variables hold the names "Susan" and "Peter".

To do that you need to change the int to String. This changes what time of data the variable holds.
You'll also need to surround the "Susan" and "Peter" in double quotes, just like you've done down the bottom in the system.out.println().



Cheers Charcoal
forgot about the name variables that needed to be covered when changing it from numbers

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 19th April 2014 - 02:55 AM