About 4,770,000 results
Open links in new tab
  1. java - How to number each line in the output using a for loop?

    Feb 10, 2015 · How do I get the number sequence?? Number each line in the output, and add a message at the end of the loop that says how many times the message was printed. So if the user enters 3, your program should print this:

  2. java - How do we print loop output in single line? - Stack Overflow

    Dec 31, 2018 · Just add a print of a new line after for loop calling primeNumbers. for(int i=2;i<=num;i++) { primeNumbers(i); } System.out.print("\n"); // or System.out.println();

  3. java - Printing output in a loop and printing a newline - Stack Overflow

    Jan 7, 2015 · Just add a print line statement: System.out.println(); // add this line System.out.println("Factorial of number " + n + " is :" + fact);

  4. Java For Loop - GeeksforGeeks

    Apr 17, 2025 · Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program is executed. Let's go through a simple example of a Java while loop: [GFGT

  5. Java Output Values / Print Text - W3Schools

    You learned from the previous chapter that you can use the println() method to output values or print text in Java: System.out.println("Hello World!"); You can add as many println() methods as you want. Note that it will add a new line for each method: System.out.println("Hello World!"); System.out.println("I am learning Java.");

  6. Java Output Examples for Beginners - boxoflearn.com

    Dec 17, 2024 · Java provides several built-in methods for generating output, with the most commonly used being System.out.print() and System.out.println(). Java’s output mechanism is simple and powerful, enabling developers to display …

  7. Java for Loop (With Examples) - Programiz

    Java for loop is used to run a block of code for a certain number of times. The syntax of for loop is: // body of the loop . Here, The initialExpression initializes and/or declares variables and executes only once. The condition is evaluated. If the condition is …

  8. display text on the same line in a loop - compsci.ca

    Nov 20, 2010 · System.out.print() will print text without automatically appending a newline character on the end (as opposed to the println method, which does append the newline character.) When you want to go to a new line, just print a newline (\n) character.

  9. For Loop Program in Java with Examples - Sanfoundry

    Write a Java Program to Display Numbers from 1 to 10 using For Loop. We use For Loop in which we initialise a variable to 1 and increments each time by 1 till we reach 10. The loop breaks when variable attains value 11. In this method, we will display numbers from 1 to 10 using For Loop.

  10. java - How can I print to the same line? - Stack Overflow

    Oct 29, 2011 · So all you need is to print this every time you need to refresh the line. Here is the code which prints Line 1 (second variant) : System.out.println("Line 1 (first variant)"); System.out.print("\33[1A\33[2K"); System.out.println("Line 1 (second variant)");