#1 Java Program To print Numbers in Below pattern:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
- package com.javatutorial;
- public class NumbersFormat {
- public static void main(String[] args) {
- int num=15;
- int temp=1;
- for (int i = 1; i <= num; i++)
- {
- for (int k = i; k <num; k++)
- System.out.print(" ");
- for (int j =1; j <= i; j++){
- System.out.print("" +temp+ " ");
- temp++;
- if(temp>15){
- break;
- }
- }
- System.out.println();
- if(temp>15){
- break;
- }
- }
- }
- }
- 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
# Java Program to print Numbers in Below Format:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
- package learnJavaOnline;
- public class NumbersFormat {
- public static void main(String[] args) {
- int r, c;
- for (r = 1; r <= 10; r++) {
- for (c = 1; c <= r; c++) {
- System.out.print(c + " ");
- }
- System.out.println("");
- }
- }
- }
- 1
- 1 2
- 1 2 3
- 1 2 3 4
- 1 2 3 4 5
- 1 2 3 4 5 6
- 1 2 3 4 5 6 7
- 1 2 3 4 5 6 7 8
- 1 2 3 4 5 6 7 8 9
- 1 2 3 4 5 6 7 8 9 10
#3 Java Program to print numbers in below format
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
- package com.learnJava;
- public class NumbersFormat {
- public static void main(String[] args) {
- int r, c;
- for (r = 1; r <= 10; r++) {
- for (c = 1; c <= 10-r; c++) {
- System.out.print(c + " ");
- }
- System.out.println("");
- }
- }
- }
Output:
- 1 2 3 4 5 6 7 8 9
- 1 2 3 4 5 6 7 8
- 1 2 3 4 5 6 7
- 1 2 3 4 5 6
- 1 2 3 4 5
- 1 2 3 4
- 1 2 3
- 1 2
- 1
No comments:
Post a Comment