In this chapter we will make a pyramid using console application in java. Okay first, open your IDE. I use netbeans 6.8 with jdk1.6.0_18. After that, make a new project and new class (Class Name : "pyramid").
Source Code
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
int _heightpiramid = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Tutorial make pyramid in Java");
System.out.println("-----------------------------");
System.out.print("Entry height of pyramid : ");
_heightpiramid = sc.nextInt();
System.out.println("Result : ");
for (int x = 0; x < _heightpiramid; x++) {
for (int z = (_heightpiramid - 1) - x; z > 0; z--) {
System.out.print(" ");
}
for (int y = 0; y <= x; y++) {
System.out.print("*");
}
for (int y = 1; y <= x; y++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
Note :
1. Enter a number of height pyramid
I hope this tutorial can help you..^^
Tuesday, January 25, 2011
Make Pyramid in Console Application (Java)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment