Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java Method Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Shah




PostPosted: 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
Sponsor
sponsor
jcollins1991




PostPosted: 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")
Shah




PostPosted: 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




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Shah




PostPosted: 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




PostPosted: 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"...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Shah




PostPosted: 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




PostPosted: Tue Dec 28, 2010 3:13 pm   Post subject: RE:Java Method Help

I figured it out thanks jcollins1991 and Tony
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: