Results 1 to 2 of 2
  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

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
  •