contoh file 1
Nama file : contoh Pyramid_1.java
public class contoh_Pyramid_1 {
public static void main(String[] args) {
for(int i=5; i>0 ;i--){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
Output
run:
*****
****
***
**
*
*
**
***
****
*****
BUILD SUCCESSFUL (total time: 5 seconds)
contoh file 2
Nama file : contoh_Pyramid_2.java
public class contoh_Pyramid_2 {
public static void main(String[] args) {
for(int i=5; i>0 ;i--){
for(int j=0; j < i; j++){
System.out.print(j+1);
}
System.out.println("");
}
}
}
Output
run:
12345
1234
123
12
1
BUILD SUCCESSFUL (total time: 1 second)
contoh file 3
Nama file : contoh_Pyramid_3.java
public class contoh_Pyramid_3 {
public static void main(String[] args) {
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
System.out.print(j+1);
}
System.out.println("");
}
}
}
Output
run:
1
12
123
1234
12345
BUILD SUCCESSFUL (total time: 0 seconds)
contoh file 4
Nama file : contoh_Pyramid_4.java
public class contoh_Pyramid_4 {
public static void main(String[] args) {
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
for(int i=5; i>0 ;i--){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
Output
run:
*
**
***
****
*****
*****
****
***
**
*
BUILD SUCCESSFUL (total time: 0 seconds)
contoh file 5
Nama file : contoh_Pyramid_5.java
public class contoh_Pyramid_5 {
public static void main(String[] args) {
for(int i=5; i>0 ;i--){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
Output
run:
*****
****
***
**
*
BUILD SUCCESSFUL (total time: 0 seconds)
program di atas dibuat menggunakan netbeans, selamat mencoba semoga bermanfaat
No comments:
Post a Comment