Dan Hasilnya Adalah

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Dan Hasilnya adalah

Dan untuk Bentuk bintang Terbalik codenya adalah

Dan hasil tampilannya adalah

dan Juga ada bentuk-bentuk lainnya

/** To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package segitiga;
import java.util.Scanner;
/**
*
* @author www.seventine.wordpress.com
*/
public class Main {
public static void Segitiga1( int variabel){
String show = “”;
for(int i=variabel;i>=1;i–){
for (int j=i; j>=1; j–) {
show += “* “;
}
show += “\n”;
}
System.out.println(show);
}
public static void Segitiga2( int variabel){
int j,k;
String show = “”;
for(int i=variabel;i>=1;i–){
for(j=variabel;j>i;j–){
show += ” “;
}
for(k=1;k<=i;k++){
show += “* “;
}
show += “\n”;
}
System.out.println(show);
}
public static void main(String[] args) {
int value;
int key;
do{
System.out.println(“Enter your triangle amount: “);
Scanner in = new Scanner(System.in);
value=in.nextInt();
System.out.println(“Output Triangle 1 : “);
Segitiga1(value);
System.out.println(“Output Triangle 2 : “);
Segitiga2(value);
System.out.println(“Press 1 to Continue and 0 to exit : “);
Scanner press = new Scanner(System.in);
key=press.nextInt();
}while(key==1) ;
}
}

Hasilnya adalah

Enter your triangle amount:


5
Output Triangle 1 :
*****
****
***
**
*

Output Triangle 2 :
*****
****
***
**
*

class SegitigaBintang {
public static void main(String [] args){
int i,j,k=7;
for(i=1;i<=k;i++){
for(j=0;j<=i;j++){
System.out.print(" ");
}
for(j=k;j<=i;k--){
System.out.print(" *");
}
System.out.print("\n");
}
}
}
for (int x=0; x<=5; x++){
for (int y=0; y<=x; ++y){
if (x==y){

System.out.println("_x=y");

}else System.out.print("x|y");
}
}

the code above will print:


*
+*
++*
+++*
++++*
+++++*

public class Segi


{
public static void main (String args[])
{
int a,b,c;
int v=5;
for(a=0;a<=v;a++)
{
for(b=0;b<=a;b++)
{
System.out.print(" ");
}

for(c=0;c>=(a-v);c--)
{
System.out.print("*");
}
for(c=0;c<(v-a);c++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

You might also like