Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- public class FloydsTriangle {
- public static void main(String[] args) {
- int noOfRows = 0;
- int theNumber = 0;
- JFrame frame = new JFrame("Floyd's Triangle!");
- String rows = JOptionPane.showInputDialog(frame, "Input the number of row/s for the Floyd's Triangle");
- if(!rows.isEmpty() ){
- noOfRows = Integer.valueOf(rows);
- }
- String number = JOptionPane.showInputDialog(frame, "Input the number 'n' for the Floyd's Triangle");
- if(!number.isEmpty() ){
- theNumber = Integer.valueOf(number);
- }
- System.out.printf("The no. of row/s are '%d'.\n", noOfRows);
- System.out.printf("The number 'n' is '%d'.\n", theNumber);
- int start = 1;
- for (int i = 1; i <= noOfRows ; i++) {
- for (int j = 1; j <=i ; j++) {
- System.out.print("("+ start + "*" + theNumber + ")" + " ");
- start++;
- }
- System.out.println();
- }
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement