Advertisement
RahulShaw

Floyd's Triangle

Oct 27th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JOptionPane;
  3.  
  4.  
  5. public class FloydsTriangle {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int noOfRows = 0;
  10.        
  11.         int theNumber = 0;
  12.        
  13.         JFrame frame = new JFrame("Floyd's Triangle!");
  14.  
  15.        
  16.         String rows = JOptionPane.showInputDialog(frame, "Input the number of row/s for the Floyd's Triangle");
  17.        
  18.             if(!rows.isEmpty() ){
  19.            
  20.                 noOfRows = Integer.valueOf(rows);
  21.            
  22.             }
  23.            
  24.        
  25.         String number = JOptionPane.showInputDialog(frame, "Input the number 'n' for the Floyd's Triangle");
  26.        
  27.             if(!number.isEmpty() ){
  28.                
  29.                 theNumber = Integer.valueOf(number);
  30.            
  31.             }
  32.        
  33.        
  34.         System.out.printf("The no. of row/s are '%d'.\n", noOfRows);
  35.        
  36.         System.out.printf("The number 'n' is '%d'.\n", theNumber);
  37.        
  38.        
  39.         int start = 1;
  40.        
  41.         for (int i = 1; i <= noOfRows ; i++) {
  42.            
  43.             for (int j = 1; j <=i ; j++) {
  44.                 System.out.print("("+ start + "*" + theNumber + ")" + " ");
  45.                 start++;
  46.             }
  47.            
  48.             System.out.println();
  49.         }
  50.        
  51.         System.exit(0);
  52.  
  53.     }
  54.    
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement