MODUL 2 (TIPE DATA, KEYWORD, VARIABEL, OPERATOR DAN KONFERSI DATA)

*** KONVERSI


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

/**
 *
 * @author anik nurul
 */
public class Tugas1 {
    public static void main(String [] args)
{
String nama="Joko Waluyo";
double kalkulus=80;
double pti=90;
double daspro=80;
double nilai_rata=(kalkulus+pti+daspro)/3;
int nilai_rata2=(int) ((kalkulus+pti+daspro) / 3);
System.out.println("Nilai Double Rata Rata "+nama+" Adalah "+nilai_rata);
System.out.println("Nilai Integer Rata Rata "+nama+" Adalah "+nilai_rata2);
//Konfersi Integer Ke String
String a=String.valueOf(nilai_rata2);
String hasil="Nilai Rata Rata "+nama+" Adalah "+a;
System.out.println("Hasil Konfersi String Ke Integer "+hasil);
//Konfersi String Ke Double
double b=Double.parseDouble(a);
System.out.println("Hasil Konfersi String Ke Double "+b);
//Konfersi String Ke Integer
int c=Integer.parseInt(a);
System.out.println("Hasil Konfersi String Ke Integer "+c);
// Casting Integer Ke Double
double d=(double)c;
System.out.println("Hasil Casting Integer Ke Double "+d);
int e=(int)d;
System.out.println("Hasil Casting Double Ke Integer "+e);
}
}

*** OPERATOR


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

/**
 *
 * @author anik nurul
 */
public class Tugas2 {
    public static void main(String [] args)
{
int a=10; int b= 12; int c=9; int e=2; int f=9; int n=90;
int hasil,jumlah=0;
boolean cek,tes=false;
String lulus="";
//Proses Operator Aritmatika
int tambah=a+b, kurang= a-b, bagi= a/b, kali= a*b, sisa= a%e;
System.out.print(tambah+"\n+ = "+kurang+"\n- = "+bagi+"\n/ = "+kali+"\nx = "+sisa+"\n% = ");
//Proses Operator Relasi
boolean a1=b>c,a2=b>=c,a3=b<c,a4=b<=c,a5=b==c,a6=b!=c;
    System.out.println("b>c = "+a1+" b>=c = "+a2+" b<c = "+a3+" b<=c = "+a4+" b==c = "+a5+" b!=c = "+a6);
//Proses Operator Increment Decrement
int g=++a, h=--a, i=a++, j=a--, k=a;
System.out.println("a++="+g+" --a= "+h+" a== "+i+" a--= "+j+" a= "+k);
//Proses Operator Logika
boolean b1=(a>b)||(c==f), b2=(a==b)&(b==++f),b3=(b>a)^(f==--a);
    System.out.println("(a>b)||(c==f)"+ b1+"(a==b)&(b==++f)"+b2+"(b>a)^(f==--a)"+b3);

//Proses Operator Kondisi
String Lulus =(n>=60)?"Lulus" : "Ngulang";
    System.out.println(Lulus);
}
}


 *** MENCARI RATA RATA TRUS DI KONVERSI











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

/**
 *
 * @author anik nurul
 */
import javax.swing.*;
public class Tugas3 {
    private static String rata_rata;
    public static void main(String[] args) {
//      JOptionPane.showInputDialog(null,rata_rata+" bukan angka mas beroo!!" + "\nMasukkan angka saja mas berooo!!"); //memberikan massage alert kesalahan        
        int rata_rata=(23+45+6+-45+-2)/5;
        System.out.println(rata_rata);
        String string_rata_rata = String.valueOf("Nilai rata-rata = "+rata_rata);// int ke String
        Double double_rata_rata= Double.valueOf(rata_rata);// int ke double
       
        System.out.println("konfersi tipe data string = "+string_rata_rata);
        System.out.println("konfersi tipe data double = "+double_rata_rata);
    }
   
}

        /*
      
                String name = JOptionPane.showInputDialog("What is your name?");
                System.out.print(name);
                System.exit(0);
            }
        }*/

*** MENGHITUNG LUAS DAN KELILING LINGKARAN DENGAN r DI INPUTKAN


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

/**
 *
 * @author anik nurul
 */
import javax.swing.JOptionPane;
public class Tugas4 {
    public static void main(String[] args) {
        String nilai ="";
        nilai = JOptionPane.showInputDialog("Masukkan Nilai r ");
        String msg = "Luas Lingkaran "+nilai;
        JOptionPane.showMessageDialog(null, msg);
        double r = 10;
        double Luas= 3.14 * r * r;
        double Keliling=3.14*2*r;
        System.out.println("Luas  Lingkaran "+Luas+"\nKeliling Lingkaran "+Keliling);
   
                }
 
}


*** MENGHITUNG GAJI

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

/**
 *
 * @author anik nurul
 */
public class Tugas5 {
    public static void main(String[] args)
    {
       
        int gajiKotor=1000*9600;  
        int potongan = 10/100* gajiKotor;
   
        int gajiBersih = gajiKotor-potongan;
        System.out.println("Gaji Bersih adalah Rp."+gajiBersih);
    } 
}


Comments

Popular posts from this blog

Pengalaman KRS an yang pertama

30 Menit Sesi Akhir

Memasukkan Gambar Pada Eclipse