Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OneToTenPattern {
- /**
- * Program: OneToTenPattern.java
- * Purpose: Alternative algorithm for creating number pattern (single for loop).
- * Creator: Chris Clarke
- * Created: 21.05.2015
- */
- /*
- Java program to create the following pattern:
- 1
- 23
- 456
- 78910
- */
- public static void main(String[] args) {
- int perLine=1; // number of numbers per line
- int count=0; // numbers printed in current line
- for (int n=1; n<=10; n++) { // n loops from 1 to 10
- System.out.print(n); // print n
- count++; // increment counter
- if (count==perLine) { // if we've printed the right number of numbers for this line
- System.out.println(); // new line
- perLine++; // increment numbers per line
- count=0; // reset counter
- } // if
- } // for
- } // main()
- } // class OneToTenPattern
Advertisement
Add Comment
Please, Sign In to add comment