Selasa, 08 November 2016

Bilangan Prima 1-100

                                                                 Program Java 
Menentukan bilangan prima dari 1-100 dipemrograman JAVA menggunakan :
Perulangan For...Loop
Perulangan While...Loop
Perulangan Do While...Loop


1. PERULANGAN FOR...LOOP
public static void main(String[] args) {
        int bilangan, pembagi;
        for (bilangan = 1; bilangan <= 100; bilangan++) {
            int x = 0;
            for (pembagi = 1; pembagi <= bilangan; pembagi++) {

                if (bilangan % pembagi == 0) {
                    if (bilangan != pembagi) {
                        x = 1;
                    }
                    if (x != 1 && bilangan == pembagi) {
                        System.out.println(bilangan);
                    }
                }
            }
        }

    }
}

2. PERULANGAN WHILE...LOOP

namespace While
{
    class Perulangan
    {
        public void counter()
        {
            int hitung=1;
            while(hitung<=100)
            {
                Console.WriteLine();
                Console.WriteLine(hitung);
                hitung=Convert.ToInt99(hitung*2);
            }
            
        }
    }
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Bilangan kelipatan 1 (1-100)");
            Console.WriteLine();
            Console.WriteLine("^^^^^^^^^^ While ^^^^^^^^^");
            Perulangan mulai=new Perulangan();
            mulai.counter();
            Console.WriteLine();
            Console.WriteLine();
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

3. PERULANGAN DO WHILE...LOOP

namespace DoWhile

{

class Perulangan

    {
        public void counter()
        {
            int nilai=1;
            do
            {
                Console.Write(" "+nilai);
                nilai=Convert.ToInt99(nilai+nilai);
            }
            while(nilai<=100);
        }
    }

Read More ->>

Sabtu, 15 Oktober 2016

CARA MENGKONVERSI SUHU DI PEMROGRAMAN JAVA

import java.util.;
public class KonversiSuhu {
public static void main(String[] args) {
Celcius fromCelcius = new Celcius();
        Fahrenheit fromFahrenheit = new Fahrenheit();
        Reamur fromReamur = new Reamur();
        Kelvin fromKelvin = new Kelvin();
double Fahrenheit, Kelvin,Celcius,Reamur;
        boolean valid=false;
        Scanner input = new Scanner(System.in);
while(valid!=true)
{
            System.out.println("Program Konversi Suhu");
            System.out.print("Masukkan suhu awal dan nilainya (D/F/R/K) (misal : 100 C):");
            SuhuAwal=input.nextDouble();
            Awal = input.next().charAt(0);
 switch(Awal){
                case 'C':
                    Reamur = fromCelcius.toReamur();
                    Fahrenheit = fromCelcius.toFahrenheit();
                    Kelvin = fromCelcius.toKelvin();
                    System.out.println("Suhu awal ="+SuhuAwal+" Celcius\nHasil:");
                    System.out.println("Fahrenheit : "+Fahrenheit);
                    System.out.println("Kelvin : "+Kelvin);
                    System.out.println("Reamur : "+Reamur);
                    valid=true;
                    break;
case 'F':
                    Celcius = fromFahrenheit.toCelcius();
                    Reamur = fromFahrenheit.toReamur();
                    Kelvin = fromFahrenheit.toKelvin();
                    System.out.println("Suhu awal ="+SuhuAwal+" Fahrenheit\nHasil:");
                    System.out.println("Celcius : "+Celcius);
                    System.out.println("Kelvin : "+Kelvin);
                    System.out.println("Reamur : "+Reamur);
                    valid=true;
                    break;
                case 'K':
                    Celcius = fromKelvin.toCelcius();
                    Reamur = fromKelvin.toReamur();
                    Fahrenheit = fromKelvin.toFahrenheit();
                    System.out.println("Suhu awal ="+SuhuAwal+" Kelvin\nHasil:");
                    System.out.println("Celcius : "+Celcius);
                    System.out.println("Fahrenheit : "+Fahrenheit);
                    System.out.println("Reamur : "+Reamur);
                    valid=true;
                    break;
                case 'R':
                    Celcius = fromReamur.toCelcius();
                    Fahrenheit = fromReamur.toFahrenheit();
                    Kelvin = fromReamur.toKelvin();
                    System.out.println("Suhu awal ="+SuhuAwal+" Reamur\nHasil:");
                    System.out.println("Celcius : "+Celcius);
                    System.out.println("Fahrenheit : "+Fahrenheit);
                    System.out.println("Kelvin : "+Kelvin);
                    valid=true;
                    break;
                default :
                    System.out.println("Masukkan suhu secara benar [C,F,K,R]");
            }
        }
    }
    }
 
 
Read More ->>
Diberdayakan oleh Blogger.