Author |
Message |
Shah
|
Posted: Tue Dec 28, 2010 12:49 pm Post subject: Java Method Help |
|
|
Hey everybody, I need help with some programming code in Java, any assistance would be welcome, this is what is troubling me I want to put a piece code from a method into a different method. For example :
import java.util.Scanner;
public static void Input {
Scanner read = new Scanner (System.in);
String getInput;
System.out.println("What is your name?");
getInput= read.nextLine();
}
public static void Output {
// show the getInput value HERE
}
Is it possible for it happen ?
Thanks,
Shah |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
jcollins1991
|
Posted: Tue Dec 28, 2010 12:53 pm Post subject: Re: Java Method Help |
|
|
Send the variables as parameters to the function.
code: |
public static void Output (String output) {
System.out.println(output)
}
|
and then call it
|
|
|
|
|
 |
Shah
|
Posted: Tue Dec 28, 2010 1:09 pm Post subject: RE:Java Method Help |
|
|
I'm still a bit of confused, I'm trying to get the value of getInput from the Input Method appear in the Output method , and than from that I can call the method Output into the main method. |
|
|
|
|
 |
Tony

|
Posted: Tue Dec 28, 2010 1:20 pm Post subject: RE:Java Method Help |
|
|
The example about should be sufficient. Did you get that (the example) to work? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Shah
|
Posted: Tue Dec 28, 2010 1:40 pm Post subject: RE:Java Method Help |
|
|
Yeah I got it to work, but it's not what I was looking for... |
|
|
|
|
 |
Tony

|
Posted: Tue Dec 28, 2010 2:00 pm Post subject: RE:Java Method Help |
|
|
you have a variable called getInput. Lets say that it holds a value of "hello"... |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Shah
|
Posted: Tue Dec 28, 2010 2:13 pm Post subject: RE:Java Method Help |
|
|
Yes i know that, but i want the value of getInput displayed in a different method |
|
|
|
|
 |
Shah
|
Posted: Tue Dec 28, 2010 3:13 pm Post subject: RE:Java Method Help |
|
|
I figured it out thanks jcollins1991 and Tony |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|