mercredi 11 janvier 2017

can u tell me a little change in my own written pascal logic

i have just take the format and spacing but can any one tell me a single change to get the values which print in actual pascal triangle program in java...

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package patterns;

/**
 *
 * @author Love Poet
 */
public class p11 {

    public static void main(String args[]) {
        int row, col, count = 0;
        for (row = 1; row <= 5; row++) {
            for (col = 1; col <= 9; col++) {
                if (((row + col) % 2 == 0) && (row + col >= 6)) {
                    System.out.print("* ");
                    count++;
                } else if (count == row) {
                    break;
                } else {
                    System.out.print("  ");
                }
            }
            count = 0;
            System.out.println();
        }
    }
}

Output:-

        * 
      *   * 
    *   *   * 
  *   *   *   * 
*   *   *   *   * 

Aucun commentaire:

Enregistrer un commentaire