I Need A Java Code That Will Help Me Output A Diamond Shape?
I am trying to write a Program that will Accept an integer between 5 and 10 and use the value as the number of rows to print out all 3 figures below. Could someone help me with this problem please. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 Answers - Sort by: Date | Rating
The code is very simple. Try this
import java.io.*;
public class myDiamondInput {
public static void main(String [] args) throws IOException {
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String input;
int num;
System.out.println("input number: ");
input = stdin.readLine ();
num = Integer.parseInt(input);
int d = num;
int e = 0;
for (int a = 0; a <= num; a++) {
for (int c = d; c>= 1; c-- )
System.out.print(" ");
d-=1;
for (int b = 1; b <= a; b++)
System.out.print ("* ");
System.out.println();
}
num-=1;
for (int a = 0; a<=num; a++) {
for (int b = num; b > a; b--)
System.out.print (" *");
System.out.println();
for (int c = 0; c <= e; c++)
System.out.print(" ");
e+=1;
}
}
}
import java.io.*;
public class myDiamondInput {
public static void main(String [] args) throws IOException {
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String input;
int num;
System.out.println("input number: ");
input = stdin.readLine ();
num = Integer.parseInt(input);
int d = num;
int e = 0;
for (int a = 0; a <= num; a++) {
for (int c = d; c>= 1; c-- )
System.out.print(" ");
d-=1;
for (int b = 1; b <= a; b++)
System.out.print ("* ");
System.out.println();
}
num-=1;
for (int a = 0; a<=num; a++) {
for (int b = num; b > a; b--)
System.out.print (" *");
System.out.println();
for (int c = 0; c <= e; c++)
System.out.print(" ");
e+=1;
}
}
}
0
0
Guest
answered 3 months ago
- Write A Program To Display A String With An Embedded Quote:"Sachin Has Played A Game Of His Life"?
- Why Java Is Papular In Market?
- What Is Plateform?
- How Can I Use Dmp File In Java?
- Can You Write A Program Called InheritanceTest.java To Support An Inheritance Hierarchy For Class Point–Square–Cube?
- Why We Use This Method In Java?
- Why Java Not Supports Multiple Inheritence?
- A Java Program To Get Sports Marks In Student Package And Print Total Marks Of Student?
- The Project Aims To Implement A JAVA Parser? 1- Classes And Functions 2- Arithmetic/logic Expressions 3- If Statement
- How To Get Java On My Lg 260?
- Write A Java Program To Store A Number Find If It Is Positive Or A Negative Number If Positive Print I Am The First?
- How To Update The Sim 3 Expansion?
- What Is An Attribute In Java?
- Do I Have To Write A Main Method In Every Class I Create?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Servlet In Java?

New Comment - Comments are editable for 5 min.