Java Main Topics

Extra Topics

HOT! J-e.g. DB-e.g. Git API Tools
IQ-Architecture IQ-Kafka IQ-General Cloud IQ-Spring Cloud IQ-Java General IQ-Serialization IQ-Collection IQ-Concurrency IQ-GC IQ-Database General IQ-Design Pattern IQ-XSLT IQ-MicroServices IQ-MicroServices Pattern IQ-Hibernate IQ-Spring General IQ-Spring Boot IQ-JS IQ-Bootstrap IQ-Ext-JS IQ-WS IQ-SOAP WS IQ-REST WS IQ-1 IQ-2 IQ-Scenerio
D-Language Fundamentals D-Declaration D-Access Control D-Enum D-Object Orientation D-Operators & Assignments D-Collections D-Concurrency D-I/O & NIO Drill D-Inner Classes D-Threads D-Garbage Collection D-Serialization D-JDBC D-Spring Boot D-WebService
Core Java Spring Microservices Web Services Cloud Cloud Design Pattern Architecture ORM Markup-Script UI DB PHP Ubuntu
Other

Contact Me

Java Example

Java 8 Sample Ex
Arrays
Array Simple
Array 2 Dimensation
Bubble Sort
String
String Tricks
String words count
String Sort words WO
Collection
M- List Duplicate Element
Java 8 - List
Java 8 - Hash Map
Logical / Puzzle
Diamand Structure
Arm Strong Number

    Diamand Structure and Pyramid structure (first half portion)

    If you give input as 4 then it will create the structure for 4 size Diamand Structure. I just put the = instead of space to undersand better.
    			package javaRefresh;
    			import java.util.Scanner;
    			
    			public class DiamandStructure {
    			
    				public static void main(String[] args) {
    					//Take the input from the user
    					Scanner scan = new Scanner(System.in);
    					System.out.print("Enter no of Rows for Diamond Structure :");
    			
    					int n = scan.nextInt();
    					int space = n - 1;
    					//Create the first upper part of Diamond
    					for (int i = 1; i <= n; i++) {
    						for (int c = 1; c <= space; c++) {
    							System.out.print("=");
    						}
    						space--;			
    						for (int c = 1; c <= (2 * i - 1); c++) {
    							System.out.print("*");
    						}
    						System.out.println();
    					}
    					//============above part use as Pyramid structure ========
    					//Create the Second down part of Diamond
    					space = 1;
    			
    					for (int d = 1; d <= (n - 1); d++) {
    						for (int c = 1; c <= space; c++) {
    							System.out.print("=");
    						}
    						space++;
    						for (int c = 1; c <= (2 * (n - d) - 1); c++) {
    							System.out.print("*");
    						}
    						System.out.println();
    					}
    				}			
    			}
    			
    Output -
    			Enter Number of Rows for Diamond Structure : 4
    			===*
    			==***
    			=*****
    			*******
    			=*****
    			==***
    			===*
    			

© COPYRIGHT 2014-2018 JAVAREFRESH - ALL RIGHTS RESERVED by MCB