0% found this document useful (0 votes)
25 views

Import Java - Io. Class Tulisbacafile Mport Java - Util.scanner

The document contains code for several Java programs. The first program writes lines of text to a file and then reads and prints the lines. The second program defines a class that takes user input to calculate the area of a triangle or trapezoid. The third program defines a SubString class and uses the substring method to extract part of a string. The fourth program takes user input of an amount of money in Rupiah and calculates the number of each banknote denomination needed.

Uploaded by

Ega Shela M
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Import Java - Io. Class Tulisbacafile Mport Java - Util.scanner

The document contains code for several Java programs. The first program writes lines of text to a file and then reads and prints the lines. The second program defines a class that takes user input to calculate the area of a triangle or trapezoid. The third program defines a SubString class and uses the substring method to extract part of a string. The fourth program takes user input of an amount of money in Rupiah and calculates the number of each banknote denomination needed.

Uploaded by

Ega Shela M
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.io.

*; class tulisbacafile { public static void main(String[]abcd) { String str; FileWriter fw; BufferedWriter bw; try { fw = new FileWriter("coba2.txt"); bw = new BufferedWriter(fw,1024); bw.write("baris kesatu"+"\r\n"); bw.write("baris kedua\r\n"); bw.write("baris ketiga\r\n"); bw.write("baris keempat\r\n"); bw.flush(); bw.close(); } catch (IOException e) { System.err.println("File writing error"); } FileReader fr; BufferedReader br; try { fr = new FileReader("coba2.txt"); br = new BufferedReader(fr); while ((str=br.readLine()) != null) { System.out.println (str); } br.close(); } catch (IOException e) { System.err.println("File read eroor"); } } }

mport java.util.Scanner; } } class bbb_tes { public static void main (String []args) { int pil; double sa,st,sl; Scanner s = new Scanner (System.in); System.out.println("Pilihan"); System.out.println("1.Menghitung Luas segitiga"); System.out.println("2.Menghitung Piramida rata kiri terbalik"); System.out.println("Silahkan pilih : "); System.out.println("================ ========================"); pil=s.nextInt(); switch (pil){ case 1 : System.out.print("Masukan Alas : "); sa=s.nextDouble(); System.out.print("Masukan Tinggi"); st=s.nextDouble(); sl=sa*st*0.5; System.out.println("luasnya adalah : " + sl + "cm"); break; case 2 : }

} }

class SubString { public static void main ( String [] argument) { String a= "Universitas"; String b; b=a.substring(2,5); System.out.println(b); //b=a.substring(4,3); //System.out.println(b); } }

import java.util.Scanner; class hitung_duit { public static void main (String[]abc) { int Rp; Scanner s= new Scanner (System.in); System.out.print("masukkan duit lho :"); Rp = s.nextInt(); int [] z= {100000, 50000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100}; for (int a=0; a<z.length; a++) {int banyak_lembar=Rp/z[a]; System.out.println("Lembar "+ z[a]+" \t= "+ banyak_lembar); Rp= Rp%z[a];

You might also like