import java.io.*;
class EkoShift21
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String firstnumber="";
String secondnumber="";
String type= "";
System.out.println("please input first number :");
firstnumber = br.readLine();
System.out.println("please input second number :");
secondnumber = br.readLine();
System.out.println("please select type of operation :");
System.out.println("1 untuk penjumlahan ");
System.out.println("2 untuk pengurangan ");
System.out.println("3 untuk perkalian ");
System.out.println("4 untuk pembagian ");
System.out.println("please input options :");
type = br.readLine();
int k,l,m,o,p,q;
double r;
k = Integer.parseInt(firstnumber);
l = Integer.parseInt(secondnumber);
m = Integer.parseInt(type);
o = k+l;
p = k-l;
q = k*l;
r = k/l;
switch (m)
{
case 1: System.out.println("Hasilnya pertambahannya adalah "+o);
break;
case 2: System.out.println("Hasilnya pengurangannya adalah "+p);
break;
case 3: System.out.println("Hasilnya perkaliannya adalah "+q);
break;
case 4: System.out.println("Hasilnya pembagiannya adalah "+r);
break;
}}}
Eko Rudi Gunadarma
Minggu, 18 Maret 2012
ini adalah code syntax dalam pemrograman Swing dalam java
import javax.swing.JOptionPane;
class EkoSwing
{
public static void main(String[] args)
{
int banyak;
String [][] bentuk = new String [80][30];
banyak=Integer.parseInt(JOptionPane.showInputDialog(null,"masukkan banyak;"));
for (int i=0;i<banyak;i++ ){
for (int j=0;j<banyak;j++ ){
if((i==j)||(i+j==banyak-1)){
bentuk [i][j]="*";
}
else{
bentuk[i][j]=" ";
}
System.out.print(bentuk[i][j]);
}
System.out.println();
}
}
}
class EkoSwing
{
public static void main(String[] args)
{
int banyak;
String [][] bentuk = new String [80][30];
banyak=Integer.parseInt(JOptionPane.showInputDialog(null,"masukkan banyak;"));
for (int i=0;i<banyak;i++ ){
for (int j=0;j<banyak;j++ ){
if((i==j)||(i+j==banyak-1)){
bentuk [i][j]="*";
}
else{
bentuk[i][j]=" ";
}
System.out.print(bentuk[i][j]);
}
System.out.println();
}
}
}
ini adalah code syntax untuk pemrograman EntryAdd dalam program java
public class EntryAdd
{
private String[] name = new String[100];
private String[] address = new String[100];
private String[] phone = new String[100];
private String[] email = new String[100];
private static int entryCount;
private static int index;
private static int entry;
private static int entry1;
public static int getEntryCount()
{
return entryCount;
}
public String getName(int index)
{
return name[index];
}
public String getAddress(int index)
{
return address[index];
}
public String getPhone(int index)
{
return phone[index];
}
public String getEmail(int index)
{
return email[index];
}
public void setEntry(String name, String address, String phone, String email, int index)
{
this.name[index] = name;
this.address[index] = address;
this.phone[index] = phone;
this.email[index] = email;
}
}
{
private String[] name = new String[100];
private String[] address = new String[100];
private String[] phone = new String[100];
private String[] email = new String[100];
private static int entryCount;
private static int index;
private static int entry;
private static int entry1;
public static int getEntryCount()
{
return entryCount;
}
public String getName(int index)
{
return name[index];
}
public String getAddress(int index)
{
return address[index];
}
public String getPhone(int index)
{
return phone[index];
}
public String getEmail(int index)
{
return email[index];
}
public void setEntry(String name, String address, String phone, String email, int index)
{
this.name[index] = name;
this.address[index] = address;
this.phone[index] = phone;
this.email[index] = email;
}
}
ini adalah code syntax untuk menampilkan BookAdd pada program java
import java.io.*;
public class BookAdd
{
public static void main(String[] args) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String choice=null, jumlah=null, back=null, add=null;
String[] name = new String[100];
String[] address = new String[100];
String[] phone = new String[100];
String[] email = new String[100];
int choicex, total=0, menu=0;
EntryAdd newEntry = new EntryAdd();
while (menu==0)
{
System.out.println();
System.out.println(" _______________________________ ");
System.out.println("|___________MAIN_MENU___________|");
System.out.println("|_1._Add_Entry__________________|");
System.out.println("|_2._Remove_Entry_______________|");
System.out.println("|_3._Show_All_Entries___________|");
System.out.println("|_4._Update_Entry_______________|");
System.out.println("|______________END______________|");
System.out.println();
System.out.print("From the menu above, pick one number: ");
choice = in.readLine();
choicex = Integer.parseInt(choice);
int x=choicex;
switch (x)
{
case 1:
System.out.print("Input number of entry you want to add: ");
add = in.readLine();
total = Integer.parseInt(add);
for (int i=0; i<total; i++)
{
if (total>1)
{
System.out.println("Input entry NO"+(i+1));
}
System.out.print("Name: ");
name[i] = in.readLine();
System.out.print("Address: ");
address[i] = in.readLine();
System.out.print("Phone number: ");
phone[i] = in.readLine();
System.out.print("E-mail: ");
email[i] = in.readLine();
newEntry.setEntry(name[i], address[i], phone[i], email[i], i);
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(i+1)+"____________");
System.out.println(" Name : "+newEntry.getName(i));
System.out.println(" Address : "+newEntry.getAddress(i));
System.out.println(" Phone : "+newEntry.getPhone(i));
System.out.println(" E-mail : "+newEntry.getEmail(i));
System.out.println(" _______________END_______________");
System.out.println();
}
break;
case 2:
String del=null;
int delx;
if (total>0)
{
System.out.print("Which entry number will you delete? = ");
del = in.readLine();
delx = Integer.parseInt(del);
name[(delx-1)] = "";
address[(delx-1)] = "";
phone[(delx-1)] = "";
email[(delx-1)] = "";
newEntry.setEntry(name[(delx-1)], address[(delx-1)], phone[(delx-1)], email[(delx-1)], (delx-1));
System.out.println("Entry NO"+delx+" has been deleted.");
}
else System.out.println("You don't have any entries yet.");
break;
case 3:
if (total > 0)
{
System.out.println("Showing all entries:");
for (int j=0; j<total; j++)
{
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(j+1)+"____________");
System.out.println(" Name : "+newEntry.getName(j));
System.out.println(" Address : "+newEntry.getAddress(j));
System.out.println(" Phone : "+newEntry.getPhone(j));
System.out.println(" E-mail : "+newEntry.getEmail(j));
System.out.println(" _______________END_______________");
System.out.println();
}
}
else System.out.println("You don't have any entries yet.");
break;
case 4:
String mod=null;
int modx;
if (total>0)
{
System.out.print("Which entry number will you modified? = " );
mod = in.readLine();
modx = Integer.parseInt(mod);
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
System.out.println(" Name : "+newEntry.getName(modx-1));
System.out.println(" Address : "+newEntry.getAddress(modx-1));
System.out.println(" Phone : "+newEntry.getPhone(modx-1));
System.out.println(" E-mail : "+newEntry.getEmail(modx-1));
System.out.println(" _______________END_______________");
System.out.println();
System.out.println("Modifying entry NO"+modx+" now.");
System.out.print("Name: ");
name[(modx-1)] = in.readLine();
System.out.print("Address: ");
address[(modx-1)] = in.readLine();
System.out.print("Phone number: ");
phone[(modx-1)] = in.readLine();
System.out.print("E-mail: ");
email[(modx-1)] = in.readLine();
newEntry.setEntry(name[(modx-1)], address[(modx-1)], phone[(modx-1)], email[(modx-1)], (modx-1));
System.out.println("Showing the updated entry:");
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
System.out.println(" Name : "+newEntry.getName((modx-1)));
System.out.println(" Address : "+newEntry.getAddress((modx-1)));
System.out.println(" Phone : "+newEntry.getPhone((modx-1)));
System.out.println(" E-mail : "+newEntry.getEmail((modx-1)));
System.out.println(" _______________END_______________");
System.out.println();
}
}
System.out.print("Return to main menu? (Y/N) = ");
back = in.readLine();
if ((back.equals("N")) || (back.equals("n")))
{
menu++;
}
else if ((back.equals("Y")) || (back.equals("y")))
{
System.out.println("Returning to main menu...");
}
}
}
}
public class BookAdd
{
public static void main(String[] args) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String choice=null, jumlah=null, back=null, add=null;
String[] name = new String[100];
String[] address = new String[100];
String[] phone = new String[100];
String[] email = new String[100];
int choicex, total=0, menu=0;
EntryAdd newEntry = new EntryAdd();
while (menu==0)
{
System.out.println();
System.out.println(" _______________________________ ");
System.out.println("|___________MAIN_MENU___________|");
System.out.println("|_1._Add_Entry__________________|");
System.out.println("|_2._Remove_Entry_______________|");
System.out.println("|_3._Show_All_Entries___________|");
System.out.println("|_4._Update_Entry_______________|");
System.out.println("|______________END______________|");
System.out.println();
System.out.print("From the menu above, pick one number: ");
choice = in.readLine();
choicex = Integer.parseInt(choice);
int x=choicex;
switch (x)
{
case 1:
System.out.print("Input number of entry you want to add: ");
add = in.readLine();
total = Integer.parseInt(add);
for (int i=0; i<total; i++)
{
if (total>1)
{
System.out.println("Input entry NO"+(i+1));
}
System.out.print("Name: ");
name[i] = in.readLine();
System.out.print("Address: ");
address[i] = in.readLine();
System.out.print("Phone number: ");
phone[i] = in.readLine();
System.out.print("E-mail: ");
email[i] = in.readLine();
newEntry.setEntry(name[i], address[i], phone[i], email[i], i);
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(i+1)+"____________");
System.out.println(" Name : "+newEntry.getName(i));
System.out.println(" Address : "+newEntry.getAddress(i));
System.out.println(" Phone : "+newEntry.getPhone(i));
System.out.println(" E-mail : "+newEntry.getEmail(i));
System.out.println(" _______________END_______________");
System.out.println();
}
break;
case 2:
String del=null;
int delx;
if (total>0)
{
System.out.print("Which entry number will you delete? = ");
del = in.readLine();
delx = Integer.parseInt(del);
name[(delx-1)] = "";
address[(delx-1)] = "";
phone[(delx-1)] = "";
email[(delx-1)] = "";
newEntry.setEntry(name[(delx-1)], address[(delx-1)], phone[(delx-1)], email[(delx-1)], (delx-1));
System.out.println("Entry NO"+delx+" has been deleted.");
}
else System.out.println("You don't have any entries yet.");
break;
case 3:
if (total > 0)
{
System.out.println("Showing all entries:");
for (int j=0; j<total; j++)
{
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(j+1)+"____________");
System.out.println(" Name : "+newEntry.getName(j));
System.out.println(" Address : "+newEntry.getAddress(j));
System.out.println(" Phone : "+newEntry.getPhone(j));
System.out.println(" E-mail : "+newEntry.getEmail(j));
System.out.println(" _______________END_______________");
System.out.println();
}
}
else System.out.println("You don't have any entries yet.");
break;
case 4:
String mod=null;
int modx;
if (total>0)
{
System.out.print("Which entry number will you modified? = " );
mod = in.readLine();
modx = Integer.parseInt(mod);
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
System.out.println(" Name : "+newEntry.getName(modx-1));
System.out.println(" Address : "+newEntry.getAddress(modx-1));
System.out.println(" Phone : "+newEntry.getPhone(modx-1));
System.out.println(" E-mail : "+newEntry.getEmail(modx-1));
System.out.println(" _______________END_______________");
System.out.println();
System.out.println("Modifying entry NO"+modx+" now.");
System.out.print("Name: ");
name[(modx-1)] = in.readLine();
System.out.print("Address: ");
address[(modx-1)] = in.readLine();
System.out.print("Phone number: ");
phone[(modx-1)] = in.readLine();
System.out.print("E-mail: ");
email[(modx-1)] = in.readLine();
newEntry.setEntry(name[(modx-1)], address[(modx-1)], phone[(modx-1)], email[(modx-1)], (modx-1));
System.out.println("Showing the updated entry:");
System.out.println();
System.out.println(" _________________________________ ");
System.out.println(" ____________ENTRY_NO"+(modx)+"____________");
System.out.println(" Name : "+newEntry.getName((modx-1)));
System.out.println(" Address : "+newEntry.getAddress((modx-1)));
System.out.println(" Phone : "+newEntry.getPhone((modx-1)));
System.out.println(" E-mail : "+newEntry.getEmail((modx-1)));
System.out.println(" _______________END_______________");
System.out.println();
}
}
System.out.print("Return to main menu? (Y/N) = ");
back = in.readLine();
if ((back.equals("N")) || (back.equals("n")))
{
menu++;
}
else if ((back.equals("Y")) || (back.equals("y")))
{
System.out.println("Returning to main menu...");
}
}
}
}
Langganan:
Postingan (Atom)