uses wincrt;
var
r, luas, keliling : integer;
const phi = 3.14:real;
begin
write('masukkan jari-jari:');readln(r);
L := phi*r*r;
write('luasnya =', luas);
k := 2*phi*r;
write('kelilingnya =', keliling);
readln;
end.
Program Konversi Bilangan
public static int pangkat (int a, int b){
int hasil=1;
for(int i=1;i<=b;i++){
hasil=hasil*a;
}
return hasil;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String bin = "";
String bilbiner = "";
int nilaiawal = 0;
int nilaisisa;
int hasilbagi = 0;
String hasil;
nilaiawal = Integer.parseInt(txtnilai.getText());
if (jComboBox1.getSelectedIndex()== 0){
hasilbagi = nilaiawal/2;
while(hasilbagi>=1){
nilaisisa = nilaiawal % 2;
if (nilaisisa == 0){
bin="0";
}else if (nilaisisa == 1){
bin ="1";
}bilbiner = bin + bilbiner;
nilaiawal = hasilbagi;
hasilbagi = nilaiawal/2;
}
if (nilaiawal>0){
hasil = "1"+bilbiner;
}else {
hasil = "0";
}
txthasil.setText(String.valueOf(hasil));
}else if (jComboBox1.getSelectedIndex()==1){
String biner = txtnilai.getText();
int n, sum;
int hasilbiner;
char b[]= new char [1000];
n=biner.length();
sum=0;
for (int i=1;i<=n;i++){
b[i]=biner.charAt(i-1);
}
for (int i=n-1;i>=0;i--){
if(b[n-i]=='0'){
sum=sum+0*pangkat(2,i);
}else if(b[n-i]=='1'){
sum=sum+1*pangkat(2,i);
}
}
hasilbiner=sum;
txthasil.setText(String.valueOf(hasilbiner));
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtnilai.setText("");
txthasil.setText("");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
PROGRAM BINTANG MENGGUNAKAN
PASCAL
program bintang_segitiga_siku;
uses wincrt;
var a, b, n : integer;
begin
write ('Masukkan angka : '); readln (n);
for a := 1 to n do
begin
for b := 1 to a do
begin
write ('*');
end;
writeln (' ');
end;
readln;
end.
program bintang_persegi;
uses wincrt;
var n, a, b, c : integer;
begin
clrscr;
write ('Masukkan angka : ');readln(n);
for a := 1 to n do
begin
write ('*');
end;
writeln;
for b := 2 to n-1 do
begin
write ('*');
for c := 1 to n-2 do
begin
write (' ');
end;
write ('*');
writeln;
end;
for a := 1 to n do
begin
write ('*');
end;
readln;
end.
program bintang_segitiga_samakaki;
uses crt;
var n, a, b : integer;
begin
clrscr;
write ('Masukkan angka : ');readln (n);
for a := 1 to n do
begin
for b := 0 to n-a do
begin
write (' ');
end;
for b := 1 to (2*a)-1 do
begin
write ('*');
end;
writeln;
end;
readln;
end.
program UTS;
uses crt;
var n, a, b : integer;
begin
clrscr;
write ('Masukkan angka : '); readln (n);
for a := 1 to n do
begin
for b := 1 to (2*n)-a do
begin
write (' ');
end;
for b:= 1 to (2*a)-1 do
begin
write ('*');
end;
writeln;
end;
for a := 1 to n do
begin
for b := 1 to n-a do
begin
write (' ');
end;
for b := 1 to a do
begin
write ('*');
end;
for b := 1 to (2*n)-1 do
begin
write (' ');
end;
for b := 1 to a do
begin
write ('*');
end;
writeln;
end;
for a := 1 to n-1 do
begin
for b := 1 to a do
begin
write (' ');
end;
for b := 1 to n-a do
begin
write ('*');
end;
for b := 1 to (2*n)-1 do
begin
write (' ');
end;
for b := 1 to n-a do
begin
write ('*');
end;
writeln;
end;
for a := 0 to n-1 do
begin
for b := 1 to n+a do
begin
write (' ');
end;
for b := 2 to (2*n)-(a*2) do
begin
write ('*');
end;
writeln;
end;
readln;
end.
Program Konversi Suhu
Sebelumnya, importkan terlebih dahulu
“import java.text.DecimalFormat;”
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double hasil = 0;
DecimalFormat model = new DecimalFormat("#0.0#");
double suhuawal = 0;
suhuawal = Double.parseDouble(txtsuhu.getText());
if (jComboBox1.getSelectedIndex() == 0){
hasil = (suhuawal + 459.67)/1.8;
}else{
hasil = (suhuawal / 1.8) - 459.67;
}
txthasil.setText(String.valueOf(model.format(hasil)));
}
“import java.text.DecimalFormat;”
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double hasil = 0;
DecimalFormat model = new DecimalFormat("#0.0#");
double suhuawal = 0;
suhuawal = Double.parseDouble(txtsuhu.getText());
if (jComboBox1.getSelectedIndex() == 0){
hasil = (suhuawal + 459.67)/1.8;
}else{
hasil = (suhuawal / 1.8) - 459.67;
}
txthasil.setText(String.valueOf(model.format(hasil)));
}
Tidak ada komentar:
Posting Komentar