notes102506 - import java.io Output to a file Filewriter fw...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 //scope int n //available global for(n=0,. ........ ) for(int n. ....... ) //available only for for loop //multiple initializations in loop int n,m for(n=0,m=5 ... ...){} OR ... ...){}//another way //////////////////////////////////////////// Code4-9 - Sentinel (escape) //////////////////////////////////////////// int sum=0 while(i != -1){ sum+= i System.out.println("Enter next Sale") } //////////////////////////////////////////// Nested loops //////////////////////////////////////////// for(h=0 h<24 h++){ for(m=0 m<60 m++){ for(s=0 s<60 s++){ System.out.println(h+":"+m+":"+s) } } } //////////////////////////////////////////
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: import java.io.* Output to a file Filewriter fw = new FileWriter("data.txt") //opens a file PrintWriter pw = new PrintWriter(fx) //connects to FileWriter pw.println("it is Wednesday!") pw.close() ////////////////////////////////////////// input from a file FileReader fr = new FileReader("data.txt") //open existing file BufferedReader br = new BufferedReader(fr) String s = br.readLine() //reads 1st line in data.txt Sheet1 Page 2 while(s != null){ //null means end of file (eof) System.out.println(s) s = br.readLine() } br.close()...
View Full Document

This note was uploaded on 03/11/2008 for the course CS 140 taught by Professor Kerbs during the Winter '06 term at Cal Poly Pomona.

Page1 / 2

notes102506 - import java.io Output to a file Filewriter fw...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online