Contoh Program Java : Looping atau Pengulangan
Script nya bisa anda lihat dibawah ini.
import javax.swing.*;
public class tugas_bintang1
{
public static void main (String[] args)
{
int x;
x=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang ?"));
for(int i=1; i<=x; i++)
{
for(int j=1; j<=x; j++)
{
if(j<=i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
public class tugas_bintang1
{
public static void main (String[] args)
{
int x;
x=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang ?"));
for(int i=1; i<=x; i++)
{
for(int j=1; j<=x; j++)
{
if(j<=i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
Input :
0 komentar:
Posting Komentar