bersatu kita teguh bercerai kita runtuh

bersatu kita teguh bercerai kita runtuh

Selasa, 10 Mei 2011

array 1 dimensi

public class array
{
    public static void main(String [] ar)

    {int [] um={4,5,2,3};
     String [] nm={"joko","Budi","Yeni","Nino"};
     System.out.println("No Nama Umur");
     for(int i=0 ; i<4;i++)
         System.out.println((i+1)+"  "+nm[i]+"  "+um[i]);
    }
}
Read More... array 1 dimensi

array 2 dimensi kamus

import java.util.Scanner;
public class array_2_dimensi
{public static void main (String[] args)
{ Scanner input=new Scanner(System.in);

  String [][] kata={
{"one","satu"},{"cow","sapi"},{"run","lari"},{"red","merah"},{"man","orang"}

  };
  String katadicari;

  System.out.print("Kata Yang Di Cari = ");
  katadicari=input.nextLine();
  int i,k;k=-1;
  for (i=0;i<5;i++)
          {
      if(kata[i][0].equals(katadicari))
      {
          k=i;
      }
    }
  if (k==-1)
  {System.out.println ("kata yang di cari tidak ditemukan");
    }
 else
  {
      System.out.println("terjemahan = "+kata [k][1]);
 }
    }
}
Read More... array 2 dimensi kamus

While

public class while2 {
     public static void main(String[] args)
     {
         int i=3;
         while (i<=18)
         {
             System.out.println(i+","+""); i+=3;

    }
}
}
Read More... While

for

public class tugas1
{
    public static void main(String[] args)
    {


        for(int i=2; i<=10; i+=2)
            System.out.println(i+","+"");


}
}
Read More... for

Faktorial

import java.util.Scanner;
public class faktorial
{
    public static void main(String[] args)
    {
     int f;
     int n;
     Scanner input=new Scanner(System.in);
     System.out.print("masukkan nilai f: ");
     f=input.nextInt();
     System.out.print("masukkan nilai n: ");
     n=input.nextInt();

    
     for (int i=1 ; i<=n ; i++) f*=i;
     System.out.println(n+"! ="+f);
 }

}
Read More... Faktorial

Pembalik array

import java.util.Scanner;
public class array
{
    public static void main(String [] ar)

    {Scanner input=new Scanner (System.in);
        {
        int i;
        int[] data=new int [5];
        for(i=0; i<5; i++)
        {
            System.out.print( "data ke "+i+" = ");
            data [i]=input.nextInt();
        }
        System.out.print("data array :");
        for(i=0;i<5;i++)
        {
            System.out.print(" "+data[i]);
            }
        System.out.print("  ");
        System.out.print("     ");
            for(i=4;i>=0;i--)
            {
            System.out.print(" "+data[i]);

    }
 }
    }
    }
Read More... Pembalik array

for +Faktorial

public class tugas1
{
    public static void main(String[] args)
    {
        int f=0 ; int n=10;
        for(int i=2; i<=n; i+=2)f+=i;
            System.out.println(n+", ="+f);
}
}
Read More... for +Faktorial

bintang 4

public class tugas_bintang4 {
    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();
                        }
        }
    }
Read More... bintang 4

bintang3

import javax.swing.*;
public class tugas_bintang2 {
    public static void main (String[] args){
        int baris;
        baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak Bintang ?"));
                         for (int i=1;i<=baris;i++) {
                            for (int j=1;j<=baris;j++){
                                if (i<=j)
                                    System.out.print("*");
                                else
                                    System.out.print(" ");

                            }
                            System.out.println();
                        }
    }
}
Read More... bintang3

Bintang2

import javax.swing.*;
public class tugas_bintang {
    public static void main(String[] args){
        int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukkan Banyak Bintang ?"));
        x=baris+1;
for (int i=1;i<=baris;i++){
    for (int j=1;j<=baris;j++){
        y=i+j;
        if (x<=y)
            System.out.print("*");
        else
            System.out.print(" ");
    }
    System.out.println();
}
    }
}
Read More... Bintang2

BINTANG1 JAVA BY Heru Uchiha

/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();
                        }
    }
}
Read More... BINTANG1 JAVA BY Heru Uchiha