Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-02-2012, 05:24 PM   PM User | #1
anonymous9
New Coder

 
Join Date: Jan 2012
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
anonymous9 is an unknown quantity at this point
Inputting String into program

I'm having problems getting my program to run and take in a phone number as a string. One string is the area code and the other is the 7 digit number.


Code:
import java.util.Scanner;

public class Telephone {

	public static String areaCode;
	private String localNumber;
	private Object myConsole;
	private Object prompt;
	private static String area;
	private static String number;

	public Telephone(int areaCode) {
		System.out.println("Please Enter Area Code:");

		String prompt = area;
	}

	public static String getNumber1() {

		return area;

	}

	public void setName1(String number) {
		this.area = area;

	}

	public String toString1() {
		return "Phone Number: " + area;

	}

	public static String getNumber() {

		return areaCode;

	}

	public void setName(String number) {
		this.area = area;

	}

	public String toString() {
		return number;

	}
}
Code:
import java.io.Console;
import java.util.Scanner;

public class Number {
	public static void main(String[] args) {
		Console c = System.console();

		String phoneNumber = Telephone.getNumber();

		Scanner input = new Scanner(System.in);

		System.out.println("What is the employee's name?"); // prompt

		phoneNumber = input.nextString(); // read employee name from user

	}

}
anonymous9 is offline   Reply With Quote
Old 03-06-2012, 09:39 PM   PM User | #2
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
What kind of problems are you having? Scanner is the correct way to do it if you are using a console application.
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:12 PM.


Advertisement
Log in to turn off these ads.