class bacastringandfile
{
public static void main (String [] args)
{
try
{
FileInputStream fstream = new FileInputStream("myfile.txt");
DataInputStream datainput = new DataInputStream(fstream);
while (datainput.available()!=0)
{
String data = datainput.readLine();
System.out.println(data);
}
datainput.close();
}
catch (Exception x)
{
System.out.println("File Input Error");
}
}
}
program A3d;
uses crt;
var
a:array[1..2,1..3,1..3] of shortInt;
i,j,k:byte;
begin
clrscr;
a[1,1,1]:=1;
a[1,1,2]:=2;
a[1,2,1]:=3;
a[1,2,2]:=4;
a[2,1,1]:=5;
a[2,1,2]:=6;
a[2,2,1]:=7;
a[2,2,2]:=8;
a[1,1,3]:=9;
a[1,2,3]:=1;
a[2,1,3]:=2;
a[2,2,3]:=3;
for i:= 1 to 2 do
begin
for j:= 1 to 2 do
begin
for k:= 1 to 3 do write(a[i,j,k]);
writeln;
end;
end;
readln;
end.
java class panggil
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
public class TestForm extends JFrame {
JButton btnPanggil = new JButton("Panggil Form lain");
public TestForm() {
btnPanggil.setMnemonic('P');
btnPanggil.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Form_kedua b = new Form_kedua();
b.show();
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
this.setTitle("Test Memanggil Form lain");
btnPanggil.setBounds(new Rectangle(90,10,250,20));
this.getContentPane().add(btnPanggil,null);
this.setSize(500,200);
Dimension layar = Toolkit.getDefaultToolkit().getScreenSize();
int L = (layar.width - this.getSize().width) / 2;
int T = (layar.height - this.getSize().height) / 2;
this.setLocation(L,T);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
TestForm form_satu_awal = new TestForm();
}
}
import java.io.*;
class HargaBuncis
{
public static void main(String args[])
{
String x;
int harga=0,jumlah=0,n=0; // cobain kalau int harga,jumlah,n;
try
{
FileInputStream fstream = new FileInputStream("c:/hargabuncis.txt");
DataInputStream dataInput = new DataInputStream(fstream);
while (dataInput.available() !=0)
{
x=dataInput.readLine();
harga=Integer.parseInt(x);
n=n+1;
jumlah=jumlah+harga;
System.out.println ("Harga Buncis hari ke "+n+" "+harga);
}
dataInput.close();
}
catch (Exception e)
{
System.err.println("File input error");
}
double rata2=(double) jumlah/n;
// cobain kalau pake double rata2=jumlah/n; hasilnya spt apa?
System.out.println ("Harga Buncis rata-rata "+rata2);
}
}
import java.io.*;
class tulisbaca
{
public static void main(String[]args)
{
try
{
FileOutputStream simpen=new FileOutputStream("tulisbaca");
PrintStream panggil=new PrintStream(simpen);
panggil.println("Muhammad Amir");
panggil.println("20094350144");
panggil.println("3c(sore)");
panggil.close();
}
catch (Exception e)
{
System.err.println("GAGAL COY");
}
System.out.println("KESIMPEN");
{
try
{
FileInputStream buka=new FileInputStream("tulisbaca");
DataInputStream lagi=new DataInputStream(buka);
while (lagi.available()!=0)
{
String hasil=lagi.readLine();
System.out.println(hasil);
}
lagi.close();
}
catch (Exception e)
{
System.err.println("GAGAL COY");
}
System.out.println("SUKSES");
}
}
}
program poin;
uses crt;
type
typestring = string[15];
penunjukstring = ^typestring;
var
nama : penunjukstring;
begin
clrscr;
nama^:='turbo pascal';
writeln(nama^);
readln;
end.
program array2d;
uses crt;
var
table:array [1..3 , 1..2] of integer;
i,j :integer;
begin
clrscr;
table[1,1]:=11;
table[1,2]:=22;
table[2,1]:=33;
table[2,2]:=44;
table[3,1]:=55;
table[3,2]:=66;
for i:=1 to 3 do begin for j:=1 to 2 do
write(table[i,j]:10);
writeln;
end;
readln;
end.
Program segitiga;
uses crt;
var
alas,tinggi,luas:real;
begin
clrscr;
writeln('Masukkan alas ='); readln(alas);
writeln('Masukkan tinggi ='); readln(tinggi);
luas:=alas*tinggi/2;
writeln('Luas segitiga =',luas:0:2);
readln;
end.
program coba2;
uses crt;
type
penunjukkaryawan = ^catatankaryawan;
catatankaryawan = record
kode : string[5];
nama : string[25];
gaji : real;
end;
var
datakaryawan1,datakaryawan2,datakaryawan3,datakaryawan4,datakaryawan5 : penunjukkaryawan;
begin
clrscr;
writeln('masukkan 5 buah data karyawan :');
writeln;
writeln('karyawan ke 1');
new(datakaryawan1);
with datakaryawan1^do
begin
write('kode karyawan?'); readln(kode);
write('nama karyawan?'); readln(nama);
write('gaji karyawan?'); readln(gaji);
end;
writeln('karyawan ke 2');
new(datakaryawan2);
with datakaryawan2^do
begin
write('kode karyawan?'); readln(kode);
write('nama karyawan?'); readln(nama);
write('gaji karyawan?'); readln(gaji);
end;
writeln('karyawan ke 3');
new(datakaryawan3);
with datakaryawan3^do
begin
write('kode karyawan?'); readln(kode);
write('nama karyawan?'); readln(nama);
write('gaji karyawan?'); readln(gaji);
end;
writeln('karyawan ke 4');
new(datakaryawan4);
with datakaryawan4^do
begin
write('kode karyawan?'); readln(kode);
write('nama karyawan?'); readln(nama);
write('gaji karyawan?'); readln(gaji);
end;
writeln;
writeln('data karyawan diambil dari heap :');
writeln('_________________________________');
writeln;
writeln('kode nama gaji');
writeln;
with datakaryawan1^do writeln(kode:5, nama:25, gaji:12:2);
with datakaryawan2^do writeln(kode:5, nama:25, gaji:12:2);
with datakaryawan3^do writeln(kode:5, nama:25, gaji:12:2);
with datakaryawan4^do writeln(kode:5, nama:25, gaji:12:2);
readln;
end.
Tidak ada komentar:
Posting Komentar