
-----------------------------------
Shah
Tue Dec 28, 2010 12:49 pm

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

-----------------------------------
jcollins1991
Tue Dec 28, 2010 12:53 pm

Re: Java Method Help
-----------------------------------
Send the variables as parameters to the function.

[code]
public static void Output (String output) { 
  System.out.println(output)
}
[/code]

and then call it

[code]
Output("hello")
[/code]

-----------------------------------
Shah
Tue Dec 28, 2010 1:09 pm

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
Tue Dec 28, 2010 1:20 pm

RE:Java Method Help
-----------------------------------
The example about should be sufficient. Did you get that (the example) to work?

-----------------------------------
Shah
Tue Dec 28, 2010 1:40 pm

RE:Java Method Help
-----------------------------------
Yeah I got it to work, but it's not what I was looking for...

-----------------------------------
Tony
Tue Dec 28, 2010 2:00 pm

RE:Java Method Help
-----------------------------------
you have a variable called getInput. Lets say that it holds a value of "hello"...

-----------------------------------
Shah
Tue Dec 28, 2010 2:13 pm

RE:Java Method Help
-----------------------------------
Yes i know that, but i want the value of getInput displayed in a different method

-----------------------------------
Shah
Tue Dec 28, 2010 3:13 pm

RE:Java Method Help
-----------------------------------
I figured it out thanks jcollins1991 and Tony
