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

Thread: need help with homework!

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help with homework!

    hey guys, im new to programming and I really need help with this hw.

    Question - Write an application that takes a whole number consisting of 5 digits (declared as a variable) and displays the digits separated from one another by three spaces each. For example, the the user types in the number 12345, the application should display: 1 2 3 4 5.

    Thanks a bunch.
    Last edited by programmer12345; September 25th, 2009 at 04:56 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: need help with homework!

    Could you tell us what you have done/what you need help with? I don't want to do your homework for you.

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help with homework!

    this code will help u:
    class ttsdinesh
    {
    public static void main(String args[])
    {
    int j=0;
    int a[];
    a=new int[5];
    for(j=0;j<5;j++)
    a[j]=Integer.parseInt(args[j]);
    for(j=0;j<5;j++)
    {
    System.out.print(" "+" "+a[j]);
    }
    }
    }
    In the System.out.print('' "+" "+a[j]); line add spaces according to ur needs.
    Note: Pass ur inputs during run time itself.
    That is
    java ttsdinesh 1 2 3 4 5
    U need to give space between each digits in the input. else it will take it as a single number.

Similar Threads

  1. Homework problem (scanner problems)
    By TommyFiz in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 20th, 2009, 06:10 PM
  2. Homework - using 'IF' for 'For Loops'
    By Enzo in forum Loops & Control Statements
    Replies: 5
    Last Post: September 16th, 2009, 10:52 AM
  3. Mini Sudoku game 4x4 ( four 2x2 grids) program
    By derky in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 16th, 2009, 07:39 AM
  4. [SOLVED] What is cast operator and how to use it?
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 27th, 2009, 06:11 AM
  5. [SOLVED] Java program to prompt and display the user input number as odd or even
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 22nd, 2009, 01:19 AM