Contoh Program Java : Looping atau Pengulangan
Script nya bisa anda lihat dibawah ini.
public class tugas_bintang5
{
public static void main (String[] args)
{
int baris,m;
for(int i=1; i<=7; i++)
{
if(i<5)
{
for(int j=1; j<=4; j++)
{
if(j<=i)
System.out.print("*");
else
System.out.print(" ");
}
}
else
{
for(int j=1; j<=4; j++)
{
m=i+j;
if(m<=8)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
{
public static void main (String[] args)
{
int baris,m;
for(int i=1; i<=7; i++)
{
if(i<5)
{
for(int j=1; j<=4; j++)
{
if(j<=i)
System.out.print("*");
else
System.out.print(" ");
}
}
else
{
for(int j=1; j<=4; j++)
{
m=i+j;
if(m<=8)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
Outputnya ditampilkan pada cmd.
0 komentar:
Posting Komentar