...

View Full Version : Inputting String into program



anonymous9
03-02-2012, 06:24 PM
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.




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;

}
}




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

}

}

Aradon
03-06-2012, 10:39 PM
What kind of problems are you having? Scanner is the correct way to do it if you are using a console application.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum