Results 1 to 2 of 2
  1. #1
    JazzyJ is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default Basic String Help

    Hello Everyone!

    I am currently working on a lab for APCS and needed some guidance on Strings.

    The lab asks for a license plate to be inputed by the user, and I am asked to add up the ASCII values of the letter part of the plate to the number part.

    Here is what I have so far:

    System.out.print("Please enter the 'AAA' of your license plate: " );
    plate1 = in.next();
    System.out.print("Please enter the '###' of your license plate: ");
    plate2 = in.nextInt();
    for (int i=0; i < plate1.length(); i++)
    {
    char c = plate1.charAt(i);
    int j = (int) c;
    total1 += c;
    }
    total2 = total1+plate2;

    Obviously this is not my entire code, however I was wondering how I could make the user simply input the license plate in one line. I tried using the substring method, but got no luck.

    Basically I need assistance on taking the AAA value of the plate, finding the ASCII and adding it to the ###. Instead of taking the ASCII of the ### portion too. So I would like to be able to have the user enter AAA### on one line.

    Thanks for the help!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default

    Why do you need them split?
    Surely you can simply ask the user to enter their license plate number, and use nextLine() to read it in?

Similar Threads

  1. Basic GUI help
    By vahshir in forum New To Java
    Replies: 5
    Last Post: 10-11-2010, 01:33 AM
  2. Need really basic help!
    By anthonyalaan in forum New To Java
    Replies: 9
    Last Post: 09-12-2010, 01:43 PM
  3. String Tokenizer - Basic email validation
    By bobbyboyy in forum New To Java
    Replies: 3
    Last Post: 11-01-2009, 04:44 PM
  4. Basic Help
    By robjames in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 02:58 AM
  5. Need some really basic help
    By Mayur in forum New To Java
    Replies: 6
    Last Post: 01-24-2009, 06:00 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
  •