Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

Piramida Java Dan Python

The document contains code examples in Java and Python that print pyramid patterns using nested for loops. The Java code contains two methods, fungsiI() and fungsiII(), that each use a for loop within a for loop to print pyramids forward and backward respectively. The Python code also contains two functions, fungsi_1() and fungsi_2(), that each use a for loop within a for loop to print pyramids in the same manner as the Java methods.

Uploaded by

Alfito Z
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Piramida Java Dan Python

The document contains code examples in Java and Python that print pyramid patterns using nested for loops. The Java code contains two methods, fungsiI() and fungsiII(), that each use a for loop within a for loop to print pyramids forward and backward respectively. The Python code also contains two functions, fungsi_1() and fungsi_2(), that each use a for loop within a for loop to print pyramids in the same manner as the Java methods.

Uploaded by

Alfito Z
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java piramida

public class T1 {
    static void fungsiI(){
        for (int x = 1; x <= 5; x++) {
            for (int y = 1; y <= x; y++) {
                System.out.print("*");
            }
            System.out.println("");
        }
    }
    static void fungsiII(){
        for (int x=1; x<=5; x++){
            for (int y=5; y>= x; y--){
                System.out.print("*");
            }
            System.out.println("");
        }
    }
    public static void main(String[] args) {
        System.out.println("Fungsi I");
        fungsiI();
        System.out.println("Fungsi II");
        fungsiII();
       
    }
}

Python piramida

def fungsi_1():
    print('fungsi 1 ')
    for x in range(5):
        for y in range(x+1):
            print("*", end=" ")
        print("")
def fungsi_2():
    print('fungsi 2 ')
    for x in range(5, 0, -1):
        for y in range(0, x):
            print("*", end=" ")
        print("")
fungsi_1()
fungsi_2()

You might also like