inputan
public class FOR{
public static void main (String [] args){
int a = 0;
for (int i = 1; i<6; i++){
int j= i*2;
System.out.print(j+"+");
a= a+j;
if (j == 10){
System.out.print(" = ");
System.out.print (a);}
}
}}
outputnya
2+4+6+8+10+ = 30
Rabu, 18 Mei 2011
BINTANG 5 DAN 6
-Input Bintang_5-
public class tugas_bintang5 {
public static void main (String [] args){
int baris,m;
for(int i=1;i<=7;i++){
if(i<5){
for (int j=1;j<=4;j++){
if (j<=i)
System.out.print("*");
else
System.out.print(" ");
}}
else{
for (int j=1;j<=4;j++){
m=i+j;
if(m<=8)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
-Output-
*
**
***
****
***
**
*
-Input Bintang_6-
public class tugas_bintang6 {
public static void main (String [] args){
int baris,m,x,y,n;
for(int i=1;i<=7;i++){
if(i<=4){
for (int j=1;j<=7;j++){
if (j<=4){
m=i+j;
if (5<=m)
System.out.print("*");
else
System.out.print(" ");
}
else{
x=j-3;
if(x<=i)
System.out.print("*");
else
System.out.print(" ");
}
}}
else
for (int j=1;j<=7;j++){
if(j<=4){
y=i-3;
if(y<=j)
System.out.print("*");
else
System.out.print(" ");
}
else{
x=j-3;
y=i-3;
n=x+y;
if(n<=5)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
-Output-
*
***
*****
*******
*****
***
*
public class tugas_bintang5 {
public static void main (String [] args){
int baris,m;
for(int i=1;i<=7;i++){
if(i<5){
for (int j=1;j<=4;j++){
if (j<=i)
System.out.print("*");
else
System.out.print(" ");
}}
else{
for (int j=1;j<=4;j++){
m=i+j;
if(m<=8)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
-Output-
*
**
***
****
***
**
*
-Input Bintang_6-
public class tugas_bintang6 {
public static void main (String [] args){
int baris,m,x,y,n;
for(int i=1;i<=7;i++){
if(i<=4){
for (int j=1;j<=7;j++){
if (j<=4){
m=i+j;
if (5<=m)
System.out.print("*");
else
System.out.print(" ");
}
else{
x=j-3;
if(x<=i)
System.out.print("*");
else
System.out.print(" ");
}
}}
else
for (int j=1;j<=7;j++){
if(j<=4){
y=i-3;
if(y<=j)
System.out.print("*");
else
System.out.print(" ");
}
else{
x=j-3;
y=i-3;
n=x+y;
if(n<=5)
System.out.print("*");
else
System.out.print(" ");
}
}
System.out.println();
}
}
}
-Output-
*
***
*****
*******
*****
***
*
BINTANG 3 DAN 4
-Inputan Bintang_3-
import javax.swing.*;
public class tugas_bintang3 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (x<=y)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
*
**
***
****
-Input Bintang_4-
import javax.swing.*;
public class tugas_bintang4 {
public static void main (String [] args){
int baris;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
if (i<=j)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
import javax.swing.*;
public class tugas_bintang3 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (x<=y)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
*
**
***
****
-Input Bintang_4-
import javax.swing.*;
public class tugas_bintang4 {
public static void main (String [] args){
int baris;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
if (i<=j)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
BINTANG 3 DAN 4
-Inputan Bintang_3-
import javax.swing.*;
public class tugas_bintang3 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (x<=y)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
*
**
***
****
-Input Bintang_4-
import javax.swing.*;
public class tugas_bintang4 {
public static void main (String [] args){
int baris;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
if (i<=j)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
import javax.swing.*;
public class tugas_bintang3 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (x<=y)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
*
**
***
****
-Input Bintang_4-
import javax.swing.*;
public class tugas_bintang4 {
public static void main (String [] args){
int baris;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
if (i<=j)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
KAMUS 2
import java.util.Scanner;
public class kamus {
public static void main(String [] args){
Scanner Input=new Scanner(System.in);
String [][]kata = {{"ONE","SATU"},{"COW","SAPI"},{"RUN","LARI"},{"RED","MERAH"},{"MAN","ORANG"}};
String katadicari;
System.out.print("kata yang dicari = ");
katadicari = Input.next();
int i,k;
k=-1;
for(i=0;i<5;i++)
{
if (kata[i][0].equals(katadicari.toUpperCase()))
{
k=1;
}
}
if (k==-1)
{
System.out.println("kata yang di cari tidak di temukan");
}
else
{ System.out.println("Terjemahan = 1"+kata[k][1]);
}
}
}
public class kamus {
public static void main(String [] args){
Scanner Input=new Scanner(System.in);
String [][]kata = {{"ONE","SATU"},{"COW","SAPI"},{"RUN","LARI"},{"RED","MERAH"},{"MAN","ORANG"}};
String katadicari;
System.out.print("kata yang dicari = ");
katadicari = Input.next();
int i,k;
k=-1;
for(i=0;i<5;i++)
{
if (kata[i][0].equals(katadicari.toUpperCase()))
{
k=1;
}
}
if (k==-1)
{
System.out.println("kata yang di cari tidak di temukan");
}
else
{ System.out.println("Terjemahan = 1"+kata[k][1]);
}
}
}
BINTANG 1 DAN BINTANG 2
-Inputan bintang_1-
import javax.swing.*;
public class tugas_bintang1 {
public static void main (String [] args){
int x;
x=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=x;i++){
for (int j=1;j<=x;j++){
if (j<=i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-output-
*
**
***
****
-Inputan Bintang_2-
import javax.swing.*;
public class tugas_bintang2 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (y<=x)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
import javax.swing.*;
public class tugas_bintang1 {
public static void main (String [] args){
int x;
x=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
for(int i=1;i<=x;i++){
for (int j=1;j<=x;j++){
if (j<=i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-output-
*
**
***
****
-Inputan Bintang_2-
import javax.swing.*;
public class tugas_bintang2 {
public static void main (String [] args){
int baris,x,y;
baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
x=baris+1;
for(int i=1;i<=baris;i++){
for (int j=1;j<=baris;j++){
y=i+j;
if (y<=x)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
-Output-
****
***
**
*
BUAT JAVA
public class loop{
public static void main (String [] args){
int a = 0;
... for (int i = 1; i<6; i++){
int j= i*2;
System.out.print(j+"+");
a= a+j;
if (j == 10){
System.out.print("=");
System.out.print (a);}
}
}}
public static void main (String [] args){
int a = 0;
... for (int i = 1; i<6; i++){
int j= i*2;
System.out.print(j+"+");
a= a+j;
if (j == 10){
System.out.print("=");
System.out.print (a);}
}
}}
BUAT KAMUS DENGAN NETBAENS
import javax.swing.*;
class main{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int [] nomor = {1,2,3,4,5};
String [] Nama = {"Satu","Sapi","Lari","Merah","Orang"};
String [] Kamus = {"One","Cow","Run","Red","Man"};
System.out.println( "Daftar Kamus" );
System.out.println("No Kata" );
for(int i=0;i<5;i++)
System.out.println((i+1) + " " + Nama[i]);
JOptionPane.showMessageDialog(null, "KAMUS indonesia - inggris", "Informasi", JOptionPane.INFORMATION_MESSAGE);
int hasil;
do {
hasil = Integer.valueOf(JOptionPane.showInputDialog("masukan angka :" ));
if (hasil==nomor[0]){
JOptionPane.showMessageDialog(null, Nama[0] + " Bahasa Inggrisnya " + Kamus[0]);
}
if (hasil==nomor[1]){
JOptionPane.showMessageDialog(null, Nama[1] +"Bahasa Inggrisnya " + Kamus[1]);
}
if (hasil==nomor[2]){
JOptionPane.showMessageDialog(null, Nama[2] +" Bahasa Inggrisnya " + Kamus[2]);
}
if (hasil==nomor[3]){
JOptionPane.showMessageDialog(null, Nama[3] +" Bahasa Inggrisnya " + Kamus[3]);
}
if (hasil==nomor[4]){
JOptionPane.showMessageDialog(null, Nama[4] +" Bahasa Inggrisnya " + Kamus[4]);
} }
while (JOptionPane.showConfirmDialog(null, "Mau Coba lagi ?" )
==JOptionPane.YES_NO_OPTION);
} }
class main{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int [] nomor = {1,2,3,4,5};
String [] Nama = {"Satu","Sapi","Lari","Merah","Orang"};
String [] Kamus = {"One","Cow","Run","Red","Man"};
System.out.println( "Daftar Kamus" );
System.out.println("No Kata" );
for(int i=0;i<5;i++)
System.out.println((i+1) + " " + Nama[i]);
JOptionPane.showMessageDialog(null, "KAMUS indonesia - inggris", "Informasi", JOptionPane.INFORMATION_MESSAGE);
int hasil;
do {
hasil = Integer.valueOf(JOptionPane.showInputDialog("masukan angka :" ));
if (hasil==nomor[0]){
JOptionPane.showMessageDialog(null, Nama[0] + " Bahasa Inggrisnya " + Kamus[0]);
}
if (hasil==nomor[1]){
JOptionPane.showMessageDialog(null, Nama[1] +"Bahasa Inggrisnya " + Kamus[1]);
}
if (hasil==nomor[2]){
JOptionPane.showMessageDialog(null, Nama[2] +" Bahasa Inggrisnya " + Kamus[2]);
}
if (hasil==nomor[3]){
JOptionPane.showMessageDialog(null, Nama[3] +" Bahasa Inggrisnya " + Kamus[3]);
}
if (hasil==nomor[4]){
JOptionPane.showMessageDialog(null, Nama[4] +" Bahasa Inggrisnya " + Kamus[4]);
} }
while (JOptionPane.showConfirmDialog(null, "Mau Coba lagi ?" )
==JOptionPane.YES_NO_OPTION);
} }