Jumat, 28 Oktober 2011

looping tugas

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

/**
 *
 * @author TOSHIBA
 */
public class looptugas {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

         for(int a=1; a<=5; a++){
            for (int b=1; b<=a; b++)
                System.out.print(b);
                System.out.print("\n") ;
        // TODO code application logic here
    }
    }
}

looping

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

/**
 *
 * @author TOSHIBA
 */
public class looping {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

         for(int k=1; k<=4; k++){
            for (int j=1; j<=k; j++)
                System.out.print(k);
                System.out.print("\n");
        // TODO code application logic here
    }

    }
}

Minggu, 16 Oktober 2011

Tugas Algoritma Bilangan Prima

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

import java.util.Scanner;

/**
 *
 * @author TOSHIBA
 */
public class Bilangan_prima {
    public static void main(String[] args) {

       int n;
        System.out.println("\n Masukkan Angka yang akan diuji = ");
        Scanner input = new Scanner (System.in) ;
        n = input.nextInt();

        boolean isPrime = false;
    if (n >= 2) {
        isPrime = true;
       for (int x = 2; x < n; x++) {
        if (n % x == 0) {

                isPrime = false;

            }
        }
    }
    System.out.println("the answer is " + isPrime);
}
}

Sabtu, 15 Oktober 2011

Tugas Algoritma Nilai

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

import java.util.Scanner;

/**
 *
 * @author TOSHIBA
 */
public class nilai {
    public static void main(String[] args) {
        int n ;
        System.out.println("\n Masukkan Nilai = ");
        Scanner input = new Scanner (System.in) ;
        n = input.nextInt();

        if (n>=0 && n<=40)
            System.out.println("E");

        if (n>=41 && n<=50)
            System.out.println("D");

        if (n>=51 && n<=60)
            System.out.println("C");

        if (n>=61 && n<=70)
            System.out.println("B");

        if (n>=71 && n<=100)
            System.out.println("A");

        if (n>100)
            System.out.println("Eror");
    }
}

Selasa, 11 Oktober 2011

Tugas Algoritma Persegi

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

import java.util.Scanner;

/**
 *
 * @author TOSHIBA
 */
public class luas_bujursangkar {

    public static void main(String[] args) {
        int s ;
        int h ;
        int k ;
        System.out.println("\n Masukkan sisi = ");
        Scanner input = new Scanner (System.in);
        s = input.nextInt() ;

        h = s * s ;
        System.out.println("Luas ="+h);

        k = 4 * s ;
        System.out.println("Keliling ="+k);

    }

}

Tugas Algoritma Persegi Panjang

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package indra;

import java.util.Scanner;

/**
 *
 * @author TOSHIBA
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    int p  ;
    int l ;
    int h ;
    int k ;
        System.out.println("\n Masukkan Panjang = ");
        Scanner input = new Scanner (System.in) ;
        p = input.nextInt();

        System.out.println("\n Masukkan Lebar = ");
        Scanner in = new Scanner (System.in);
        l = input.nextInt();

        h = p*l ;
        System.out.println("Hasil dari Luas =" +h);

        k = 2*p + 2*l ;
        System.out.println("Hasil dari Keliling =" +k);
    }

}