/**
* @(#)mynmenu.java
*
*
* @author Widyawati
* @version 1.00 2013/11/15
*/
import javax.swing.*;
public class mymenu
{
public static void main (String args[])
{
do
{
int pil=Integer.parseInt(JOptionPane.showInputDialog
("MENU\n 1. While\n 2. Deret\n 3.Nilai\n 4. Exit\n Masukkan Pilihan [1..4]"));
switch(pil)
{
case 1:
int nilai=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai : "));
while (nilai >= 1)
{
JOptionPane.showMessageDialog(null, "Aku Anak Soleh",
"Output",JOptionPane.INFORMATION_MESSAGE);
nilai--;
}
System.out.println("\n");
break;
case 2:
int a=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Deret : "));
String gmbr = "Segitiga \n";
for(int i=1;i<=a;i++)
{
for(int j=1;j<=i;j++)
{
gmbr += "*"+" ";
}
gmbr += "\n";
}
gmbr +="\n";
JOptionPane.showMessageDialog(null, gmbr, "Segitiga",JOptionPane.INFORMATION_MESSAGE);
break;
case 3:
int kondisi=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai : "));
if (kondisi > 60)
{
JOptionPane.showMessageDialog(null, "Selamat Anda Lulus","Output",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null, "Maaf Anda Gagal","Output",JOptionPane.INFORMATION_MESSAGE);
}
System.out.println("\n");
break;
case 4:
System.exit(0);
default:
JOptionPane.showMessageDialog(null, "Silahkan Pilih Dari [1..4]",
"Anda Salah Pilih",JOptionPane.WARNING_MESSAGE);
}
}
while(true);
}
}
Jumat, 15 November 2013
Program Perulangan 3 Pada JAVA
import java.util.*;
public class segitiga3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c,d,e;
System.out.print("Masukan Angka : ");
a = input.nextInt();
e=a;
for(b=1;b<=a;b++)
{
for(d=e;d>=1;d--)
{
System.out.print(" "); //
}
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
e=e-1;
System.out.println("");
}
System.out.println("\n\n");
}
}
public class segitiga3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c,d,e;
System.out.print("Masukan Angka : ");
a = input.nextInt();
e=a;
for(b=1;b<=a;b++)
{
for(d=e;d>=1;d--)
{
System.out.print(" "); //
}
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
e=e-1;
System.out.println("");
}
System.out.println("\n\n");
}
}
Program Perulangan 2 pada JAVA
import java.util.*;
public class segitiga2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c,d,e;
System.out.print("Masukan Angka : ");
a = input.nextInt();
e=a-1;
for(b=1;b<=a;b++)
{
for(d=e;d>=1;d--)
{
System.out.print(" ");
}
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
e=e-1;
System.out.println("");
}
System.out.println("\n\n");
}
}
public class segitiga2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c,d,e;
System.out.print("Masukan Angka : ");
a = input.nextInt();
e=a-1;
for(b=1;b<=a;b++)
{
for(d=e;d>=1;d--)
{
System.out.print(" ");
}
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
e=e-1;
System.out.println("");
}
System.out.println("\n\n");
}
}
Program Perulangan 1 pada JAVA
import java.util.*;
public class segitiga {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c;
System.out.print("Masukan Angka : ");
a = input.nextInt();
for(b=1;b<=a;b++)
{
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
System.out.println("");
}
System.out.println("\n\n");
}
}
public class segitiga {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a,b,c;
System.out.print("Masukan Angka : ");
a = input.nextInt();
for(b=1;b<=a;b++)
{
for(c=1;c<=b;c++)
{
System.out.print("* ");
}
System.out.println("");
}
System.out.println("\n\n");
}
}
Program Login pada JAVA
import java.util.*;
public class login {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String a,b;
System.out.print("Masukan Username : ");
a = input.nextLine();
System.out.print("Masukan Password : ");
b = input.nextLine();
if (a.equals("widya") && b.equals("labsi"))
System.out.println("\nAnda Berhasil Login");
else
System.out.println("\nAnda Gagal Login");
System.out.println("\n\n");
}
}
public class login {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String a,b;
System.out.print("Masukan Username : ");
a = input.nextLine();
System.out.print("Masukan Password : ");
b = input.nextLine();
if (a.equals("widya") && b.equals("labsi"))
System.out.println("\nAnda Berhasil Login");
else
System.out.println("\nAnda Gagal Login");
System.out.println("\n\n");
}
}
Program Kondisi Sederhana pada JAVA
import java.util.*;
public class kondisi {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a;
System.out.print("Masukan angka : ");
a = input.nextInt();
if (a%2==0)
System.out.print("DE");
if (a%4==0)
System.out.print("JA");
if (a%8==0)
System.out.print("VU");
System.out.println("\n\n");
}
}
public class kondisi {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a;
System.out.print("Masukan angka : ");
a = input.nextInt();
if (a%2==0)
System.out.print("DE");
if (a%4==0)
System.out.print("JA");
if (a%8==0)
System.out.print("VU");
System.out.println("\n\n");
}
}
Program Array 2 Dimensi pada JAVA
/**
* @(#)dim2.java
* @author Widyawati
* @version 1.00 2013/11/7
*/
import java.util.*;
public class dim2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] matriksA= new int[10][10];
int[][] matriksB= new int[10][10];
int[][] matriksC= new int[10][10];
int k,b;
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
matriksA[b][k]= (int)(Math.random()*100);
matriksB[b][k]= (int)(Math.random()*100);
matriksC[b][k]= matriksA[b][k] + matriksB[b][k];
}
}
//Output Matriks A,B dan C
System.out.println("Matriks A");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksA[b][k]+ " ");
}
System.out.println("");
}
System.out.println("\nMatriks B");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksB[b][k]+ " ");
}
System.out.println("");
}
System.out.println("\nMatriks C(A+B)");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksC[b][k]+ " ");
}
System.out.println("");
}
}
}
* @(#)dim2.java
* @author Widyawati
* @version 1.00 2013/11/7
*/
import java.util.*;
public class dim2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] matriksA= new int[10][10];
int[][] matriksB= new int[10][10];
int[][] matriksC= new int[10][10];
int k,b;
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
matriksA[b][k]= (int)(Math.random()*100);
matriksB[b][k]= (int)(Math.random()*100);
matriksC[b][k]= matriksA[b][k] + matriksB[b][k];
}
}
//Output Matriks A,B dan C
System.out.println("Matriks A");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksA[b][k]+ " ");
}
System.out.println("");
}
System.out.println("\nMatriks B");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksB[b][k]+ " ");
}
System.out.println("");
}
System.out.println("\nMatriks C(A+B)");
for(b=0;b<3;b++)
{
for(k=0;k<3;k++)
{
System.out.print(matriksC[b][k]+ " ");
}
System.out.println("");
}
}
}
Program Array Dimensi 1 pada JAVA
/**
* @(#)dim1.java
* @author Widyawati
* @version 1.00 2013/11/7
*/
import java.util.*;
public class dim1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] array= new int[10];
int i,j,jumlah=0;
float rata;
System.out.print("Masukan Jumlah data : ");
i=input.nextInt();
for(j=0;j<i;j++)
{
System.out.print("Data ke-"+(j+1)+" = ");
array[j]=input.nextInt();
jumlah=jumlah+array[j];
}
rata=jumlah/i;
System.out.println("\n\nNilai Element Array");
for(j=0;j<i;j++)
{
System.out.println("Data ke-"+(j+1)+" = "+array[j]);
}
System.out.println("----------------- +");
System.out.println("Jumlah = "+jumlah);
System.out.println("Rata-rata = "+rata);
}
}
* @(#)dim1.java
* @author Widyawati
* @version 1.00 2013/11/7
*/
import java.util.*;
public class dim1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] array= new int[10];
int i,j,jumlah=0;
float rata;
System.out.print("Masukan Jumlah data : ");
i=input.nextInt();
for(j=0;j<i;j++)
{
System.out.print("Data ke-"+(j+1)+" = ");
array[j]=input.nextInt();
jumlah=jumlah+array[j];
}
rata=jumlah/i;
System.out.println("\n\nNilai Element Array");
for(j=0;j<i;j++)
{
System.out.println("Data ke-"+(j+1)+" = "+array[j]);
}
System.out.println("----------------- +");
System.out.println("Jumlah = "+jumlah);
System.out.println("Rata-rata = "+rata);
}
}
Program Operator Logika pada JAVA
class operatorLogika
{
public static void main(String[] args)
{
System.out.println("====Operasi AND====");
System.out.println("true && true = " + (true && true));
System.out.println("true && false = " + (true && false));
System.out.println("false && true = " + (false && true));
System.out.println("false && false = " + (false && false));
System.out.println("====Operasi OR====");
System.out.println("true || true = " + (true || true));
System.out.println("true || false = " + (true || false));
System.out.println("false || true = " + (false || true));
System.out.println("false || false = " + (false || false));
System.out.println("\n====Operasi NOT====");
System.out.println("!true = " + (!true));
System.out.println("!false = " + (!false));
System.out.println("\n====Operasi XOR====");
System.out.println("true ^ true = " + (true ^ true));
System.out.println("true ^ false = " + (true ^ false));
System.out.println("false ^ true = " + (false ^ true));
System.out.println("false ^ false = " + (false ^ false));
}
}
{
public static void main(String[] args)
{
System.out.println("====Operasi AND====");
System.out.println("true && true = " + (true && true));
System.out.println("true && false = " + (true && false));
System.out.println("false && true = " + (false && true));
System.out.println("false && false = " + (false && false));
System.out.println("====Operasi OR====");
System.out.println("true || true = " + (true || true));
System.out.println("true || false = " + (true || false));
System.out.println("false || true = " + (false || true));
System.out.println("false || false = " + (false || false));
System.out.println("\n====Operasi NOT====");
System.out.println("!true = " + (!true));
System.out.println("!false = " + (!false));
System.out.println("\n====Operasi XOR====");
System.out.println("true ^ true = " + (true ^ true));
System.out.println("true ^ false = " + (true ^ false));
System.out.println("false ^ true = " + (false ^ true));
System.out.println("false ^ false = " + (false ^ false));
}
}
Langganan:
Postingan (Atom)