Computer Science Canada

Java Method Help

Author:  Shah [ 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

Author:  jcollins1991 [ 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

code:

Output("hello")

Author:  Shah [ 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.

Author:  Tony [ 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?

Author:  Shah [ 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...

Author:  Tony [ 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"...

Author:  Shah [ 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

Author:  Shah [ Tue Dec 28, 2010 3:13 pm ]
Post subject:  RE:Java Method Help

I figured it out thanks jcollins1991 and Tony


: