5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:


import java.util.Scanner;

/**
 *
 * @author Yash
 */

public class pra10 {
    public static void main(String arg[]){
        int i,j,k,n;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the Range :");
        n=sc.nextInt();
        for(i=1;i<=n;i++){
            for(j=n;j>=i;j--){
                System.out.print(" ");
            }
            for(k=1;k<=i;k++){
                System.out.print(" *");
            }
            System.out.println(" ");
        }
        for(i=1;i<=n;i++){
            for(j=0;j<=i;j++){
                System.out.print(" ");
            }
            for(k=n;k>i;k--){
                System.out.print(" *");
            }
            System.out.println(" ");
        }
    }
}

Comments

  1. Emperor Casino | Play Online Casino Software with Real Money
    Play over choegocasino 800 casino games including popular slots, poker, blackjack, live dealer games, online scratch cards, video poker and so much 제왕 카지노 more for fun. งานออนไลน์

    ReplyDelete

Post a Comment

Popular posts from this blog

SQL Lab1: Create a Database Table for DayCare

SQL Lab 11