Tips for heathy life

Tips for heathy life
Tampilkan postingan dengan label Programming. Tampilkan semua postingan
Tampilkan postingan dengan label Programming. Tampilkan semua postingan

Senin, 25 Agustus 2014

OPERATOR arithmetic in Java SE

I want to share OPERATOR arithmetic in Java. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.
 
int i = 37;
int j = 42;
double x = 27.475;
double y = 7.22;
System.out.println("Variable values...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" x = " + x);
System.out.println(" y = " + y); //penjumlahan angka
System.out.println("Adding...");
System.out.println(" i + j = " + (i + j));
System.out.println(" x + y = " + (x + y));
//pengurangan angka
System.out.println("Subtracting...");
System.out.println(" i - j = " + (i - j));
System.out.println(" x - y = " + (x - y));
//perkalian angka
System.out.println("Multiplying...");
System.out.println(" i * j = " + (i * j));
System.out.println(" x * y = " + (x * y));
//pembagian angka
System.out.println("Dividing...");
System.out.println(" i / j = " + (i / j));
System.out.println(" x / y = " + (x / y));
//menghitung hasil modulus dari pembagian
System.out.println("Computing the remainder...");
System.out.println(" i % j = " + (i % j));
System.out.println(" x % y = " + (x % y));
//tipe penggabungan
System.out.println("Mixing tipes...");
System.out.println(" j + y = " + (j + y));
System.out.println(" i * x = " + (i * x));

Good luck.

OPERATOR Logic and Boolean AND

I want to share about OPERATOR Logic and Boolean AND. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.
------------------------
 
int i = 0;
int j = 10;
boolean test= false;
//demonstrasi &&
test = (i > 10) && (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
//demonstrasi &
test = (i > 10) & (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);

LOGIC OPERATOR and BOOLEAN OR

This is LOGIC OPERATOR and BOOLEAN OR. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.
--------------------------
int i = 0;

int j = 10;
boolean test= false;
//demonstrasi ||
test = (i < 10) || (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
//demonstrasi |
test = (i < 10) | (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);

Operator exclusive OR in Java



This is logic Operator exclusive OR. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

------------------------
boolean val1 = true;
boolean val2 = true;
System.out.println(val1 ^ val2);
val1 = false;
val2 = true;
System.out.println(val1 ^ val2);
val1 = false;
val2 = false;
System.out.println(val1 ^ val2);
val1 = true;
val2 = false;
System.out.println(val1 ^ val2);

How to make GUI Form Login dan Input data in Java SE?

I want to share how to make GUI Form Login dan Input data in Java SE. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

----------
package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class mwi {

public mwi() {

JFrame frame = new JFrame();

JButton tombol1 = new JButton("LOGIN");
JButton tombol2 = new JButton("LOGOUT");
JLabel lblPengguna = new JLabel ("Pengguna");
JLabel lblPasword = new JLabel ("Password");
JLabel lblCreated = new JLabel ("Created by :Dani:.");
final JTextField txtPengguna = new JTextField (10);
final JPasswordField txtPasword = new JPasswordField (10);

tombol1.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent event) {
txtPengguna.setText("dani");
txtPasword.setText("do u want it?");
}
});

tombol2.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(7);
}
});

Container contentPane = frame.getContentPane();
//mengeset jenis layout tanpa menggunakan jenis layout apapun
contentPane.setLayout(null);
contentPane.add(tombol1);
contentPane.add(txtPengguna);
contentPane.add(tombol2);
contentPane.add(txtPasword);
contentPane.add(lblPengguna);
contentPane.add(lblPasword);
contentPane.add(lblCreated);


//meletakkan komponen pada posisi tertentu
Insets insets = contentPane.getInsets();
//mengatur batas untuk msg2 komponen
//namaKomponen.setBounds(, ,,)
lblPengguna.setBounds(insets.left + 5, insets.top +10, 150, 20);
lblPasword.setBounds(insets.left + 5, insets.top + 40, 150, 20);
txtPengguna.setBounds(insets.left + 165, insets.top + 10, 150, 20);
txtPasword.setBounds(insets.left + 165, insets.top + 40, 150, 20);
tombol1.setBounds(insets.left + 5, insets.top + 100, 150, 20);
tombol2.setBounds(insets.left +170, insets.top +100, 150, 20);
lblCreated.setBounds(insets.left + 340, insets.top + 100, 150, 20);

frame.setTitle("Dani");
frame.pack();
frame.setSize(new Dimension(500, 160));
frame.setVisible(true);
}
public static void main(String args[]) {
new mwi();
}
}
=============================
package gui2;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.acl.Group;
import javax.swing.*;

public class Dani {

public Dani() {

JFrame frame = new JFrame();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();

JButton tombol1 = new JButton("TAMPIL");
JButton tombol2 = new JButton("BERSIH");
JButton tombol3 = new JButton("KELUAR");
JLabel lblNim = new JLabel ("NIM");
JLabel lblNama = new JLabel ("NAMA");
JLabel lblJenkel = new JLabel ("JENKEL");
JLabel lblAgama = new JLabel ("AGAMA");
final JTextField txtNim = new JTextField (10);
final JTextField txtNama = new JTextField (10);

JComboBox cmb1 = new JComboBox ();
JList lst1 = new JList();

JRadioButton opt1 = new JRadioButton("Laki-Laki");
opt1.setSelected(true);
JRadioButton opt2 = new JRadioButton("Perempuan");
ButtonGroup group1= new ButtonGroup();
group1.add (opt1);
group1.add(opt2);

cmb1.addItem("Islam");
cmb1.addItem("Kristen");
cmb1.addItem("Khatolik");
cmb1.addItem("Bindu");
cmb1.addItem("Budha");

//user interface
tombol1.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent event) {
txtNim.setText("06.12.2021");
txtNama.setText("Vieta");
}
});

tombol2.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent event) {
txtNim.setText("");
txtNama.setText("");
}
});

tombol3.addActionListener (new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
//mengeset jenis layout tanpa menggunakan jenis layout apapun
contentPane.setLayout(null);
contentPane.add(tombol1);
contentPane.add(txtNim);
contentPane.add(tombol2);
contentPane.add(txtNama);
contentPane.add(tombol3);
contentPane.add(lblNim);
contentPane.add(lblNama);
contentPane.add(lblAgama);
contentPane.add(lblJenkel);

contentPane.add(cmb1);
contentPane.add(lst1);
contentPane.add(opt1);
contentPane.add(opt2);



//meletakkan komponen pada posisi tertentu
Insets insets = contentPane.getInsets();
//mengatur batas untuk msg2 komponen
//namaKomponen.setBounds(, ,,)
lblNim.setBounds(insets.left + 5, insets.top +10, 150, 20);
lblNama.setBounds(insets.left + 5, insets.top + 40, 150, 20);
lblJenkel.setBounds(insets.left + 5, insets.top + 70, 150, 20);
opt1.setBounds(insets.left + 150, insets.top + 70, 100, 20);
opt2.setBounds(insets.left + 250, insets.top + 70, 150, 20);
lblAgama.setBounds(insets.left + 5, insets.top + 100, 150, 20);
cmb1.setBounds(insets.left +150, insets.top +100 , 150, 20);
txtNim.setBounds(insets.left + 165, insets.top + 10, 150, 20);
txtNama.setBounds(insets.left + 165, insets.top + 40, 150, 20);
tombol1.setBounds(insets.left + 5, insets.top + 200, 150, 20);
tombol2.setBounds(insets.left +150, insets.top +200, 150, 20);
tombol3.setBounds(insets.left +300, insets.top +200, 150, 20);

lst1.setBounds(insets.left + 5, insets.top + 300 ,300, 20);

frame.setTitle("Dani");
frame.pack();
frame.setSize(new Dimension(500, 300));
frame.setVisible(true);
}
public static void main(String args[]) {
new Dani();
}
}

How to display 10 integer and summation in J2SE?

I want to share how to display 10 integer and summation. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

------
/*
* IsiMatrix.java
*
* Created on November 8, 2008, 9:56 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package matrix;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author amikom
*/
public class IsiMatrix {

/** Creates a new instance of IsiMatrix */
public IsiMatrix() {
}

public static void main(String[] args)throws IOException {
int[][] matrix1=new int[3][3];
int[][]matrix2={{1,7,3},{4,10,6},{7,80,99}};
BufferedReader bf=new BufferedReader(
new InputStreamReader(System.in));
//mengisikan nilai matrix
for(int b=0;b<3 b="" br=""> for(int k=0;k<3 br="" k=""> System.out.println("Masukkan matrix[" + b + "][" + k +"]");
matrix1[b][k]=Integer.parseInt(bf.readLine());
}
}
//menampilkan isi matrix1
for(int b=0;b<3 b="" br=""> for(int k=0;k<3 br="" k=""> System.out.print(matrix1[b][k] + "\t");
}
System.out.print("\n");
}
//menampilkan isi matrix2
for(int b=0;b<3 b="" br=""> for(int k=0;k<3 br="" k=""> System.out.print(matrix2[b][k] + "\t");
}
System.out.print("\n");
}
}
}

How to display Input Output Programme in Java SE?

I want to share how to display Input Output Programme in Java SE. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

----------------
import javax.swing.JOptionPane;
public class ProgramIO{
public static void main(String[] args){
double jumlah,kurang, bagi,kali;
double bil1,bil2;
bil1=Double.parseDouble(JOptionPane.showInputDialog("Masukkan bilangan 1"));
bil2=Double.parseDouble(JOptionPane.showInputDialog("Masukkan bilangan 2"));
jumlah=bil1+bil2;
kurang =bil1-bil2;
bagi=bil1/bil2;
kali=bil1*bil2;
JOptionPane.showMessageDialog(null,"Hasil Penjumlah : + jumlah");
JOptionPane.showMessageDialog(null,"Hasil Pengurangan : + kurang");
JOptionPane.showMessageDialog(null,"Hasil Pembagian :" + bagi);
JOptionPane.showMessageDialog(null,"Hasil Perkalian :" + kali);

}
}

====

of if you use parseInt, this the code:

int bil1,bil2,jumlah,kurang,kali,bagi;
bil1=Integer.parseInt(JOptionPane.showInputDialog("Masukkan bilangan1"));
bil2=Integer.parseInt(JOptionPane.showInputDialog("Masukkan bilangan1"));
jumlah=bil1+bil2;
kurang=bil1-bil2;
kali=bil1*bil2;
bagi=bil1/bil2;
JOptionPane.showMessageDialog(null,"Hasil Penjumlah :" + jumlah);
JOptionPane.showMessageDialog(null,"Hasil Pengurangan :" + kurang);
JOptionPane.showMessageDialog(null,"Hasil Perkalian :" + kali);
JOptionPane.showMessageDialog(null,"Hasil Pembagian :" + bagi);

Rabu, 21 Januari 2009

Recurrence program in C++

public class Recurrence program {

public static void main(String[] args) {

int i;
for(i=0;i<=100; i++)
{
System.out.println("angka : "+ i);
}

}

}

Determine Prime Numbers in Java programme

I want to share program that Determine Prime Numbers in Java programme. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

package prima;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BilPrima {

public BilPrima() {
}

public static void main(String[] args) throws IOException{
int i,batasBil=0;
BufferedReader bf=new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Masukkan Batas Bil:");
batasBil=Integer.parseInt(bf.readLine());
for(i=2;i<=batasBil;i++){
int j;
for (j=2;j<=i;j++){
int n=i%j;
if(n==0){
break;
}
}
if (i==j){
System.out.println(i);
}

}

}

}

Minggu, 02 November 2008

Dispay array in C++ programme

I want to share program that display array in C++. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

#include <>
#include <>
#include <>

void main ( )
{
clrscr( );
int nilai[6] = {4,2,3,5,1,6};
int i;

for(i=1;i<6 i=""><<"="; cout <<:i endl="">

How to display 10 integer and summation of that integer in C++?


I want to share how to display 10 integer and summation. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

---------------------
#include
#include
void main ( )
{
clrscr( );
int i,x,jml;
int index[10] = {1,2,3,4,5,6,7,8,9,10};
for(i=1;i<11 br="" i=""> {
cout<<"Input integer number- "< cin< jml=x;
jml=jml+x;
cout<<"Total of integer = "< }
getch( );
}

How make program that calculates flat wake in C++?

I want to share program that calculate flat wake in C++. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

--------
#include
#include

void main ( )
{
const float phi=3.14;
float r,a,t,kell,luas;
int kode;
char pilih;

awal :
cout<<"||======================================||"<<<"||Program menghitung rumus bangun datar ||"<<<"||======================================||"<<<"\n 1. Keliling Lingkaran "<<<"2. Luas Segitiga "<<<"\n Pilihan anda adalah (1..2) = "; cin>>kode;
switch (kode)
{
case 1 :
cout<<"Anda memilih nomor 1 yaitu menghitung keliling lingkaran"; cout<<"\nMasukkan jari-jari = "; cin>>r;
kell=2*phi*r;
cout<<"\nKeliling Lingkaran = "<<<<"Anda memilih nomor 2 yaitu menghitung luas segitiga"; cout<<"\nMasukkan alas = "; cin>>a;
cout<<\nMasukkan tinggi = "; cin>>t;
luas=a*t*0.5;
cout<<"\nLuas Segitiga = "<<<<"\nMaaf anda memasukkan kode yang salah"<<<"Ingin mengulang lagi [Y/T] = "; cin>>pilih;
if ((pilih=='Y'||(pilih=='y'))
{
goto awal;
}
clrscr ( );
cout<<"\nGoodbye!!!";
}
goto awal;
getch ( );
}

How make display date in pascal?


I want to share program that display date in Pascal. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

Date Programme (input,output);

uses wincrt;
const
teks='Input date on mm dd yy(0 0 0 to stop)';
typestring=string[20];
arraytipestring=array[1..12] of tipestring;
var
month,day,year:integer;
outputdate:tipestring;
namemonth:arraytipestring;
Procedure displaynamemonth(var namemonth:arraytipestring);

begin
namemonth[1] :='Januari';
namemonth[2] :='Februari';
namemonth[3] :='Maret';
namemonth[4] :='April';
namemonth[5] :='Mei';
namemonth[6] :='Juni';
namemonth[7] :='Juli';
namemonth[8] :='Agustus';
namemonth[9] :='September';
namemonth[10] :='Oktober';
namemonth[11] :='November';
namemonth[12] :='Desember';
end;

Function DateConvert(M,D,Y:integer):

typestring;

var
day,year:tipestring;

begin
str(D,Day);
str(Y:2,year);
if year[1]:=' ' then year[1]:='0';
year:='19' + year;
if (m>=1) and (m<=12) then
DateConvert:=namemonth[M] + day + ' ' + year
else
DateConvert:='Wrong Date';
end;

Begin
displaynamemonth(namemonth);
write(teks);
readln(month,day,year);
while month and day <> 0 do
begin
resultdate:= DateConvert (month,day,year);
writeln('date numeric = ',month:3,day:3,year:3);
writeln('alpha numeric = ',hasildate);
write(teks);
readln(month,day,year);
end.

BUBLE ASCENDING in Pascal

Program Buble_Ascending_09;

uses wincrt;

var
i,k, temp:integer;
L:array[1..5] of integer;
flag:boolean;

begin
clrscr;
L[1]:=1;
L[2]:=50;
L[3]:=10;
L[4]:=3;
L[5]:=2;

flag:=false;
i:=1;
while (i<5 and="" br="" do="" flag="" not=""> begin
flag:=true;
for k:=5 downto 1 do
if(L[k] begin
temp:=L[k];
L[k]:=L[k-1];
L[k-1]:=temp;
flag:=false;
end;
inc(i);
end;

begin
for i:=1 to 5 do
writeln(L[i],' ');
writeln;
end;

end.

STACK in Pascal

Program ArrayStack;

uses wincrt;

const
max=10;

var
Top,i:byte;
Pil,temp,e:char;
Stack:array [1..max] of char;

Procedure PushAnim;

begin
for i:=1 to 18 do
begin
gotoxy(23+i,7);write(temp);{delay(30); }
gotoxy(23,7);clrEol;
end;

for i:=1 to 14-top do
begin
{delay(30); }
gotoxy(41,6+i);write(' ');
gotoxy(41,7+i);write(temp);
end;
end;

Procedure PopAnim(temp:char);

begin
for i:=1 to 14-top do
begin
{delay(30); }
gotoxy(41,22-i-top);write(temp);{delay(30); }
gotoxy(41,21-i-top);ClrEol;
end;
end;

Procedure Push(e:char);

begin
inc(top);
Stack[top]:=e;
PushAnim;
end;

Procedure Pop(e:char);

begin
if top <> 0 then
begin
e:=stack[top];PopAnim(e);
dec(top);
end else
begin
gotoxy(1,7);write(' Stack Telah Kosong ');readkey;
gotoxy(1,7);ClrEol;
end;
end.

begin
clrscr;
writeln(' ANIMASI STACK ');
writeln(' 1. Push ');
writeln(' 2. Pop ');
writeln(' 3. Quit ');
writeln(' Pilihan [1/2/3] = ');
gotoxy(59,6);write(' \ ');
gotoxy(59,8);write(' / ');
gotoxy(37,10);write(' \ /');
for i:= 1 to 11 do
begin
gotoxy(38,10+i);
if i= 11 then write(' |_______________________________| ') else
write(' |........................| ');
end;
top:=0;
repeat
gotoxy(19,5);ClrEol;
Pil:=readkey;write(Pil);
if Pil='1' then
begin
if top <> max then
begin
gotoxy(1,7);write('Masukkan suatu huruf = ');
temp:=readkey;write(temp);
Push(temp);
gotoxy(1,7);CLrEol;
end else
begin
gotoxy(1,7);write(' Stack telah penuh' );
readkey;
gotoxy(1,7);ClrEol;
end;
end else
if Pil='2' then Pop(temp);
until Pil='13';
end.

ARRAY in Pascal

uses wincrt;

var
data:array[1..7,1..7] of byte;
baris,kolom:integer;

begin

for baris:=1 to 7 do
begin
for kolom:=1 to 7 do
if (baris=kolom) or (baris+kolom=8) or (baris=4) or (kolom=4) then

data[baris,kolom]:=0
else
data[baris,kolom]:=1;
end;

for baris:=1 to 7 do
begin
for kolom:=1 to 7 do
write(' ',data[baris,kolom]);
writeln;
end;
end;

Jumat, 31 Oktober 2008

Selection Operator 1 in Java

String status = "";
int grade = 80;
//mendapatkan status pelajar
status = (grade >= 60)?"Passed":"Fail";
//print status
System.out.println( status );

Logical NOT Operator in Java

boolean val1 = true;
boolean val2 = false;
System.out.println(!val1);
System.out.println(!val2);

Relation Operator

I want to share about relation operator. You can use this code but if you copy this code and paste in your blog/website, please insert this link of article.

----------------
int i = 37;
int j = 42;
int k = 42;
System.out.println("Nilai variabel...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" k = " + k);
//lebih besar dari
System.out.println("Lebih besar dari...");
System.out.println(" i > j = " + (i > j)); //false
System.out.println(" j > i = " + (j > i)); //true
System.out.println(" k > j = " + (k > j)); //false
//lebih besar atau sama dengan
System.out.println("Lebih besar dari atau sama dengan...");
System.out.println(" i >= j = " + (i >= j)); //false
System.out.println(" j >= i = " + (j >= i)); //true
System.out.println(" k >= j = " + (k >= j)); //true
//lebih kecil dari
System.out.println("Lebih kecil dari...");
System.out.println(" i < j = " + (i < j)); //true
System.out.println(" j < i = " + (j < i)); //false
System.out.println(" k < j = " + (k < j)); //false
//lebih kecil atau sama dengan
System.out.println("Lebih kecil dari atau sama dengan...");
System.out.println(" i <= j = " + (i <= j)); //true
System.out.println(" j <= i = " + (j <= i)); //false
System.out.println(" k <= j = " + (k <= j)); //true
//sama dengan
System.out.println("Sama dengan...");
System.out.println(" i == j = " + (i == j)); //false
System.out.println(" k == j = " + (k == j)); //true
//tidak sama dengan
System.out.println("Tidak sama dengan...");
System.out.println(" i != j = " + (i != j)); //true
System.out.println(" k != j = " + (k != j)); //false

VERIFIED PASSWORD and USER NAME in Java SE

String user="";
String pwd="";
user = JOptionPane.showInputDialog("Masukkan username anda : ");
pwd = JOptionPane.showInputDialog("Masukkan password anda: ");
String msg = "Welcome to java programming language, " + user + " !";
String msg2 = " Verfikasi password anda: " + "password anda = "+pwd;
JOptionPane.showMessageDialog(null, msg);
JOptionPane.showMessageDialog(null, msg2);