/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package blogku;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Segitiga_Jam_Pasir {
public static void main(String[] args) {
int a,b,c;
Scanner input1=new Scanner(System.in);
System.out.print("masukkan angka ganjil (3-99): ");
a=input1.nextInt();
for(b=1;b<=a;b++)
{
if(b>=1 && b<=((a/2)+1))
{
for(c=1;c<=a;c++)
{
if(c>=b && c<=((a-b)+1))
{
System.out.print(a);
}
else if(!(c>=b && c<=((a-b)+1)))
{
if(a>=0 && a<=9)
{
System.out.print(" ");
}
else if(a>=10 && a<=99)
{
System.out.print(" ");
}
}
}
}
else if(b>=((a/2)+2) && b<=a)
{
for(c=1;c<=a;c++)
{
if(c>=((a-b)+1) && c<=b)
{
System.out.print(a);
}
else if(!(c>=((a-b)+1) && c<=b))
{
if(a>=0 && a<=9)
{
System.out.print(" ");
}
else if(a>=10 && a<=99)
{
System.out.print(" ");
}
}
}
}
System.out.println();
}
}
}
OUTPUT:
Selamat mencoba semoga bermanfaat :)
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package blogku;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Segitiga_Jam_Pasir {
public static void main(String[] args) {
int a,b,c;
Scanner input1=new Scanner(System.in);
System.out.print("masukkan angka ganjil (3-99): ");
a=input1.nextInt();
for(b=1;b<=a;b++)
{
if(b>=1 && b<=((a/2)+1))
{
for(c=1;c<=a;c++)
{
if(c>=b && c<=((a-b)+1))
{
System.out.print(a);
}
else if(!(c>=b && c<=((a-b)+1)))
{
if(a>=0 && a<=9)
{
System.out.print(" ");
}
else if(a>=10 && a<=99)
{
System.out.print(" ");
}
}
}
}
else if(b>=((a/2)+2) && b<=a)
{
for(c=1;c<=a;c++)
{
if(c>=((a-b)+1) && c<=b)
{
System.out.print(a);
}
else if(!(c>=((a-b)+1) && c<=b))
{
if(a>=0 && a<=9)
{
System.out.print(" ");
}
else if(a>=10 && a<=99)
{
System.out.print(" ");
}
}
}
}
System.out.println();
}
}
}
OUTPUT:
Selamat mencoba semoga bermanfaat :)

Tidak ada komentar:
Posting Komentar