|
-
Oct 20th, 2005, 07:04 AM
#1
Thread Starter
Fanatic Member
User input from the console
How can i get user input from the console?
Here is my code so far if it helps:
Code:
public class Student
{
private static String Teacher;
private static String StudentName;
/**
* Create a student
*
* @param StudentName
*/
public Student()
{
//Do nothing!
}
public static void main(String StudentName)
{
Student student = new Student();
Teacher = "Mr Whyley";
StudentName = StudentName;
//Print details
System.out.println("Student Name: " + StudentName);
System.out.println("Teacher: " + Teacher);
}
/**
* Get teacher name for a student
*
* @return Teacher
*/
public String getTeacher()
{
return Teacher;
}
}
I want to get 'StudentName' from the console.
Last edited by x-ice; Feb 25th, 2007 at 07:17 PM.
-
Oct 20th, 2005, 06:33 PM
#2
Frenzied Member
Re: User input from the console
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
use br.readLine() to get the text,but be sure to catch an io exception with this line.
*import java.io.*;
-
Oct 22nd, 2005, 09:55 AM
#3
New Member
Re: User input from the console
Shouldn't this declaration of the main method be as follows:
Code:
public static void main(String args[])
args will then contain an array of strings supplied at the command line. Another way to receive input from the command line. 
Merry Christmas
I am the real Santa Clause 
-
Oct 22nd, 2005, 11:27 AM
#4
Frenzied Member
Re: User input from the console
 Originally Posted by Santa Clause
Shouldn't this declaration of the main method be as follows:
Code:
public static void main(String args[])
args will then contain an array of strings supplied at the command line. Another way to receive input from the command line.
Merry Christmas 
I didn't catch that, but yes, your main method MUST be public, static, void, called main, and takes an array of strings as an argument.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|