Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java. How to get each line of code on seperate line when its run

  • 19-09-2014 3:57pm
    #1
    Closed Accounts Posts: 5,482 ✭✭✭


    Hey i started java last week and this is my HW

    This is my code

    /*
    *Diamond.java
    *name is here
    *19th September
    */

    public class Diamond {
    public static void main (String[] args){

    System.out.print("*");
    System.out.print ("**");
    System.out.print ("****");
    System.out.print ("**");
    System.out.print ("*");
    }
    }

    i want to get each "*" on a different line


Comments

  • Registered Users, Registered Users 2 Posts: 1,266 ✭✭✭00sully


    \n


  • Registered Users, Registered Users 2 Posts: 3 GoodThing007


    Hey i started java last week and this is my HW

    This is my code

    /*
    *Diamond.java
    *name is here
    *19th September
    */

    public class Diamond {
    public static void main (String[] args){

    System.out.print("*");
    System.out.print ("**");
    System.out.print ("****");
    System.out.print ("**");
    System.out.print ("*");
    }
    }

    i want to get each "*" on a different line

    You could use .println instead of .print

    System.out.println("*");


  • Registered Users, Registered Users 2 Posts: 8,229 ✭✭✭LeinsterDub


    You really are going to need to put in more effort.


  • Closed Accounts Posts: 5,482 ✭✭✭Hollister11


    You really are going to need to put in more effort.

    What ? This was a piece of our assignment, i can't put in any more effort the code is correct I just needed to get each line displayed on separate lines!


  • Registered Users, Registered Users 2 Posts: 14,009 ✭✭✭✭wnolan1992


    What ? This was a piece of our assignment, i can't put in any more effort the code is correct I just needed to get each line displayed on separate lines!

    What they probably meant is you need to put more effort into discovering methods like println rather than just asking. Did you read the Java APIs before posting here? Seriously, the APIs are one of the best learning resources out there IMO because when you go delving into them to find the answer to your specific question, you'll invariably find a treasure trove of other stuff that'll help you in the future.

    Either way, System.out.println() will do the trick. Or System.out.print("****\r\n")


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,299 ✭✭✭moc moc a moc


    What ? This was a piece of our assignment, i can't put in any more effort the code is correct I just needed to get each line displayed on separate lines!

    Either a bit of reading through the Java docs (or your textbook) or about thirty seconds of googling would have given you the answer, is what he's getting at.

    Every September we get a new batch of students coming in here and asking very basic questions without doing the bare minimum of searching on their own, and it gets old.


  • Moderators, Arts Moderators Posts: 10,520 Mod ✭✭✭✭5uspect


    Not only in Java, this is pretty common in many languages.


Advertisement