Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: "Separate Numbers"-Problem:Assigning Variables to User Inputs.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default "Separate Numbers"-Problem:Assigning Variables to User Inputs.

    n/a
    Last edited by SaltSlasher; June 24th, 2024 at 03:12 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Separate Numbers"-Problem:Assigning Variables to User Inputs.

    I then need to print out just the "1" and on a separate line the "5".
    Are you trying to get the first letter and the last letter from a String?
    Look at using the String class's substring method. It will allow you to get any character in a String.

    If you are working with an int value you will need to use division (/) and modulus/remainder(% ) operators.
    If you're not sure how they work, write a small simple program, use one of the operators and print out the results. Do it for many different values to see what happens. For exampl:
    int x = 10;
    System.out.println("div by 4=" + (x/4)); // show results when divided by 4
    System.out.println("rem for 4" + (x%4)) ; // show results with modulus operator

    Change the 4 and the 10 to many different values

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Separate Numbers"-Problem:Assigning Variables to User Inputs.

    Have you figured it out now?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Separate Numbers"-Problem:Assigning Variables to User Inputs.

    Glad you got it working.

    In the future Please wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "Separate Numbers"-Problem:Assigning Variables to User Inputs.

    Next step in posting code is to properly indent. The code in each nesting level of {} should be indented.
    Something like this:
    import java.util.Scanner;
    public class Number
    {
       public static void main(String[] args)
       {
     
          Scanner input = new Scanner(System.in);
     
          System.out.printf("Enter a 5 Digit Number: ");
     
          int Number = input.nextInt();
     
           ...
     
       } // end main()
     
    } // end class

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  3. using "user.dir" with mkdir
    By meisterluv in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 13th, 2010, 09:28 PM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  5. [SOLVED] Is "Public void closeFile()" a problem in the program for AS-Level computing project
    By muffin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2009, 09:12 PM