Results 1 to 8 of 8
  1. #1
    wbourget is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Help with trying to get to display a ten digit phone number as both a string and long

    Ok I'm new to java to the point where I don't know much and had four homework assignments to do and are due today at 10 Am, but i'm done with two of the assignments and I need help with trying to output a ten digit phone number as a string on one file, and write another program to write it as a long because I don't know what value I need to use in order to get the code to run properly on either one and any help is appreciated

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    You haven't even clearly described what it is you're trying to do. Post what you've written and ask specific questions.
    Get in the habit of using standard Java naming conventions!

  3. #3
    wbourget is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    import java.util. Scanner;

    public class PhoneNumberAsString
    {
    public static void main (String[] args)
    {
    int first3, mid3, last4 result, userInput;
    Scanner.keyboard = new Scanner(System.in);
    System.out.println("Please input the 10 digits of your phone number");
    userInput = keyboard.nestInt();
    first3=userInput/








    }//end main
    }//end class

    I'm trying to find out what number i would use to divide and mod the userInput for it to display a 10 digit Phone number as both a string and as a long display

  4. #4
    wbourget is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    import java.util. Scanner;

    public class PhoneNumberAsString
    {
    public static void main (String[] args)
    {
    int first3, mid3, last4 result, userInput;
    Scanner.keyboard = new Scanner(System.in);
    System.out.println("Please input the 10 digits of your phone number");
    userInput = keyboard.nextInt();
    first3=userInput/








    }//end main
    }//end class

    I'm trying to find out what number i would use to divide and mod the userInput for it to display a 10 digit Phone number as both a string and as a long display

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,598
    Rep Power
    5

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    I am still not certain what you are asking. Do you want to read in a 10 digit number and then convert it to a string without using any part of the JDK? Can you provide an example of what your input and output would look like?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,984
    Rep Power
    5

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    The joke is that a phone number is not a number, it only looks like one. But phone numbers tend to start with a zero, and that zero tends to get chopped off when you convert a phone number to an integer/long for no good reason at all.

    A phone number is text.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    wbourget is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    import java.util.Scanner;

    public class PhoneTrick_CTIM157_01_020314
    {
    public static void main (String[] args)
    {
    int first3, mid3, last4, result, userInput;
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Pleas enter the 7 digits of your phone number");
    userInput = keyboard.nextInt();
    first3 = userInput/10000;
    last4 = userInput%10000;
    System.out.println(first3);
    System.out.println(last4);




    }//end main
    }//end class

    I have to use this to display the number but I need to display it as a 10 digit compared to a 7 digit and my teacher wants me to do them both as a string and a long as both need to display the number as (123) 456-7890 and I don't know what number to use to even get this to work or what code I need to display like that
    Last edited by wbourget; 02-17-2014 at 02:33 PM. Reason: the code was wrong

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,598
    Rep Power
    5

    Default Re: Help with trying to get to display a ten digit phone number as both a string and

    If it is a string, then you need to read the String API documentation. If it is a long, then I will give you a hint. A phone number which has an area code of 123, an exchange of 456, and a subscriber number of 7890. The number in a long format would be:

    Java Code:
    long numb = ((123*1000)+456)*10000)+7890.
    But as Gimbal stated earlier, you need to be take care of proper padding when any part of the number has leading zeroes. Reading the Formatter class API may help with that.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Code to sort the leading digit of a number.
    By CreatingDrake in forum New To Java
    Replies: 24
    Last Post: 12-01-2013, 03:59 AM
  2. Removing first digit for a number...
    By andy_d in forum New To Java
    Replies: 2
    Last Post: 11-03-2013, 02:54 AM
  3. Replies: 0
    Last Post: 06-06-2012, 08:26 AM
  4. Possible combinations for a n- digit number???
    By anishr6 in forum New To Java
    Replies: 4
    Last Post: 05-25-2011, 08:55 AM
  5. select a digit in a number
    By navid in forum New To Java
    Replies: 3
    Last Post: 12-12-2010, 10:47 AM

Tags for this Thread

Posting Permissions

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