Results 1 to 6 of 6
  1. #1
    toby is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Write an application that displays the numbers 1 to 4 on the same line

    Hi, I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit and have come across a simple little problem that have no idea how to solve.
    The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space.
    Write the program using the following techniques:
    • Use one system.out.printLn statement.
    • Use four system.out.print statement.
    • Use one system.out.printf statement.


    This is what i have so far but I'm a little lost.

    Java Code:
    public class Display 
    {
            public static void main(String [] args) 
        {
                 System.out.print("1 ");
                 System.out.print("2 ");
                 System.out.print("3 ");
                 System.out.print("4 ");
                 System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
                 System.out.printf(" %s %s %s %s ");????
               }
           }
    i cant test this my console isn't working right, and i haven't finished my compiler install.
    Thanks

  2. #2
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    Maybe u better show us how u want the output to look like
    I dunno bout the others, but i don't really get what u mean
    If u wanna print a number next to another why not just write them all using the print method?:confused:
    Sorry, don't get ur point :D

  3. #3
    Join Date
    Jun 2014
    Location
    Dhaka
    Posts
    5
    Rep Power
    0

    Default Re: Write an application that displays the numbers 1 to 4 on the same line

    I m a new programmer. I m facing some problems in doing that. so, I need help for this problem.."Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space
    "

  4. #4
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Write an application that displays the numbers 1 to 4 on the same line

    Quote Originally Posted by toby View Post
    Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space.
    If I've understood this correctly, the desired output is
    Java Code:
    1 2 3 4
    You are to produce the above once for each of the techniques mentioned below:
    Quote Originally Posted by toby View Post
    • Use one system.out.printLn statement.
    • Use four system.out.print statement.
    • Use one system.out.printf statement.
    Your print() method calls are fine. I believe your println() method call should simply just put the numbers between the quote marks. printf() is more complicated, unless you're familiar with C programming. See Java For Complete Beginners - formatted strings, and for a more detailed treatment, see Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings).

  5. #5
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Write an application that displays the numbers 1 to 4 on the same line

    @Nasima Ferdous Tripti

    Don't resurrect 7 year old threads, create your own.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: Write an application that displays the numbers 1 to 4 on the same line

    I'm closing this old zombie thread.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 3
    Last Post: 12-12-2008, 12:12 PM
  2. Replies: 0
    Last Post: 03-28-2008, 08:46 PM
  3. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  4. Replies: 1
    Last Post: 07-31-2007, 04:01 AM
  5. Problem when displays in the terminal
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 02:14 AM

Posting Permissions

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