Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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
    
    	}
    
    }

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •