# JAVA - Passing multiple variables



## cc64 (Dec 21, 2007)

*The part in the first post has been solved, please read second post*

I have this method that accepts a Fahrenheit temperature from the user and converts it Celsius. I need to be able to pass both the Fahrenheit and Celsius temperature to the main method. How can I achieve this?

I am looking for it to output: " X degrees Fahrenheit is Y degrees Celsius." So far, the celsius works fine, but when I add "return fahren;" after the cels return line, it kicks back an error saying "unreachable code"

public double convert()
{
double fahren;
double cels;
System.out.println("Please enter a Fahrenheit temperature: ");
fahren = scan.nextDouble();
cels = ((fahren-32)/9) * 5;
return cels; 
}


----------



## cc64 (Dec 21, 2007)

Nevermind. I realized that I can't. Anyway, I have another question:

public void numbers()
{
int numberone;
int numbertwo;
int sum;
String fnum;
String snum;
System.out.print("Please enter two numbers from 0 to 49: ");
numberone = scan.nextInt();
numbertwo = scan.nextInt();
sum = numberone + numbertwo;
//convert sum to string
//get first char using string.charAt(0); and print to screen
//get second char using string.charAt(1); and print to screen
}

This is a method that is supposed to accept to numbers between 0 and 49 from the user, add them up and print them to the screen in string format in the form of "The first number of the sum is X and the second is Y." However, I can't seem to find a way to convert from the added integers to a string. Any ideas? My books don't seem to hold the answer...


----------



## Chicon (Jul 29, 2004)

Hi cc64,

Here are 2 ways to convert integers into strings :

*
int num = 4;
String way1 = String.valueOf(num);
String way2 = "" + num;
*


----------



## cc64 (Dec 21, 2007)

O thanks so much. That worked like a charm. Ill keep that in my memory bank. Didn;t get to use it on my assignment but thanks a lot Chicon.


----------



## Chicon (Jul 29, 2004)

You're welcome !


----------

