0% found this document useful (0 votes)
7 views1 page

Java File I/O and User Input Examples

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)
7 views1 page

Java File I/O and User Input Examples

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

import [Link].

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

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

} }

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

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

You might also like