The Artima Developer Community
Sponsored Link

Java Buzz Forum
Pattern Program in java Part-1

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Pattern Program in java Part-1 Posted: Sep 6, 2015 11:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Pattern Program in java Part-1
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
#1 Java Program To print Numbers in Below pattern:

              1
             2 3
            4 5 6
           7 8 9 10
         11 12 13 14 15


  1. package com.javatutorial;
  2. public class NumbersFormat {
  3.  
  4.  public static void main(String[] args) {
  5.  
  6.  int num=15;
  7.  int temp=1;
  8.      
  9.  for (int i = 1; i <= num; i++)
  10.  {
  11.  
  12.   for (int k = i; k <num; k++)
  13.    System.out.print(" ");
  14.    for (int j =1; j <= i; j++){
  15.  
  16.     System.out.print("" +temp+ " ");
  17.      temp++;
  18.  
  19.  if(temp>15){
  20.        break;
  21.  }
  22.  
  23.  }
  24.  
  25.   System.out.println();
  26.  
  27. if(temp>15){
  28.      break;
  29.   }
  30.  
  31. }
  32.  
  33. }

  34. }
Output:

  1.               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


  1. package com.learnJavaOnline;
  2. public class NumbersFormat {
  3. public static void main(String[] args) {
  4.  
  5. int r, c;
  6.  
  7. for (r = 1; r <= 10; r++) {
  8.  
  9. for (c = 1; c <= r; c++) {
  10.  
  11. System.out.print(c + " ");
  12.  
  13. }
  14.  
  15. System.out.println("");
  16. }
  17.  
  18. }
  19.  
  20. }
Output:
  1. 1 2 
  2. 1 2 3 
  3. 1 2 3 4 
  4. 1 2 3 4 5 
  5. 1 2 3 4 5 6 
  6. 1 2 3 4 5 6 7 
  7. 1 2 3 4 5 6 7 8 
  8. 1 2 3 4 5 6 7 8 9 
  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


  1. package com.learnJavaOnline;
  2. public class NumbersFormat {
  3. public static void main(String[] args) {
  4.  
  5. int r, c;
  6.  
  7. for (r = 1; r <= 10; r++) {
  8.  
  9. for (c = 1; c <= 10-r; c++) {
  10.  
  11. System.out.print(c + " ");
  12.  
  13. }
  14.  
  15. System.out.println("");
  16. }
  17.  
  18. }
  19.  
  20. }
Output:
  1. 1 2 3 4 5 6 7 8 9 
  2. 1 2 3 4 5 6 7 8 
  3. 1 2 3 4 5 6 7 
  4. 1 2 3 4 5 6 
  5. 1 2 3 4 5 
  6. 1 2 3 4 
  7. 1 2 3 
  8. 1 2 
  9. 1





Read: Pattern Program in java Part-1

Topic: JBoss BPM Microservices Integration Guide Based on JBoss Fuse 6.2 Previous Topic   Next Topic Topic: Scrum’s co-creator talks about the framework’s transformational effect

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use