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 6 of 6

Thread: Separating integers

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Separating integers

    Here is the problem: Write an application that inputs one number consisting of five digits from the user, separates the number into in individual digits and prints the digits separated from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should input 4 2 3 3 9.


    Here is my code so far but I am stuck. I am not taking this in school, but I want to learn this language


    mport java.util.Scanner;
    public class Seperating {

    public static void main ( String[] args)
    {
    Scanner input = new Scanner(System.in);
    int number = 0 ;




    System.out.printf("%d" , number );

    System.out.print("Enter integer");
    number = input.nextInt();





    }
    }

    but I am not getting the result I wanted what am I doing wrong


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Separating integers

    Well suggest you to use the nextLine() method of Scanner,
    store it in a String variable then use toCharArray() method of String to print each character (digits)
    that would be easier than using nextInt() method

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Separating integers

    this chapter is wants me to use division and remainder functions

  4. #4
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Separating integers

    oh I see.
    Have you tried to use Modulo ( % )?
    Did you figured it out on how to get each digit using modulo and division?

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Separating integers

    Quote Originally Posted by dicdic View Post
    oh I see.
    Have you tried to use Modulo ( % )?
    Did you figured it out on how to get each digit using modulo and division?
    No but will try that first thing in the morning,

    --- Update ---

    Will try that first thing in the morning

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Separating integers

    Please review this post where you can see how to post your code correctly, and please do so in the future.

    Thanks.

Similar Threads

  1. Separating Strings
    By Scorks in forum The Cafe
    Replies: 1
    Last Post: February 24th, 2013, 11:45 PM
  2. Literally, what's wrong with my code? Separating X and Y coordinates.
    By liamb109 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 9th, 2012, 07:53 AM
  3. Separating Digits in a String
    By Staticity in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 3rd, 2011, 06:39 AM
  4. [SOLVED] Writing Integers to .txt File; Returning Random Characters Instead of Integers
    By verbicidalmaniac in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: March 8th, 2011, 09:42 PM
  5. Determine the two smallest integers from a set of user input integers
    By bpontin in forum Loops & Control Statements
    Replies: 4
    Last Post: October 17th, 2010, 06:38 PM