java syntax and output java part 3. public class compsci { } all java programs start with a class
TRANSCRIPT
![Page 1: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/1.jpg)
Java Syntax and OutputJava Part 3
![Page 2: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/2.jpg)
public class CompSci{
}
All Java programs start with a class.
![Page 3: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/3.jpg)
public class CompSci{ public static void main(String[] args) { System.out.println("Comp Sci!"); }} OUTPUT
Comp Sci!
![Page 4: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/4.jpg)
public class CompSci{ //open brace
public static void main(String[] args) { System.out.println("Comp Sci!"); }} //close brace
Braces – You gotta have ‘em! Every classand every method must have a { and a } .
![Page 5: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/5.jpg)
© A+ Computer Science - www.apluscompsci.com
public class CompSci{ public static void main(String[] args) { System.out.println("Comp Sci!"); }}
You must put a semi-colon at the end of all Java program statements ( ; ).
![Page 6: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/6.jpg)
Never put a ; before an open { brace
;{ //illegal}; //legal
![Page 7: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/7.jpg)
Indentation
public class CompSci{ public static void main(String[] args) { System.out.println("Comp Sci!"); }}
Indent all code 3 spaces to make it easier to read.
![Page 8: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/8.jpg)
Java Output
System.outfrequently used methods
Name Use
print(x) print x and stay on the current line
println(x) print x and move to next line down
printf(s,x) print x according to s specifications
![Page 9: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/9.jpg)
System.out.print("compsci");
reference command / method
OUTPUTcompsci
![Page 10: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/10.jpg)
System.out.print("compsci");System.out.print("compsci");
OUTPUTcompscicompsci
![Page 11: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/11.jpg)
System.out.println("compsci");
OUTPUTcompsci
![Page 12: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/12.jpg)
System.out.println("compsci");System.out.println("compsci");
OUTPUTcompscicompsci
![Page 13: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/13.jpg)
System.out.println("c\tompsci");
\n newline\t tab\r carriage return\b backspace
OUTPUTc ompsci
![Page 14: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/14.jpg)
System.out.println("com\tpsci");
OUTPUTcom psci
\n newline\t tab\r carriage return\b backspace
![Page 15: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/15.jpg)
System.out.println("comp\nsci");
OUTPUTcompsci
\n newline\t tab\r carriage return\b backspace
![Page 16: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/16.jpg)
\\ outs \\" outs "\’ outs ’
System.out.println("\\compsci\"/");
OUTPUT\compsci"/
![Page 17: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/17.jpg)
\\ outs \\" outs "\’ outs ’
System.out.println("\\'comp\'sci\'/");
OUTPUT\'comp'sci'/
![Page 18: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/18.jpg)
© A+ Computer Science - www.apluscompsci.com
Escape Sequencesfrequently used combinations
Name Use
\t tabs over five spaces
\n moves to front of next line
\b deletes previous character
\r moves to front of current line
\\ nets one backslash \
\" nets one double quote "
\’ nets one single quote ’
![Page 19: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/19.jpg)
© A+ Computer Science - www.apluscompsci.com
// single-line comments/* */ block comments
//this line prints stuff on the screenSystem.out.println("stuff");
![Page 20: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/20.jpg)
Review: AboutMe Part1Create an AboutMe app that displays
your first name and last initial, your instructor’s name, and your school name on 3 separate lines.
Below the personal information, display a phrase that encourages your school team, such as “Go Plainsmen!”. Be sure this phrase is enclosed in quotations marks in your output.
![Page 21: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/21.jpg)
// single-line comments/* */ block comments
/* this line prints stuff on the screen*/System.out.println("stuff");
![Page 22: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/22.jpg)
© A+ Computer Science - www.apluscompsci.com
System.out.printf("%s","compsci\n");
OUTPUTcompsci
![Page 23: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/23.jpg)
format()
![Page 24: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/24.jpg)
© A+ Computer Science - www.apluscompsci.com
![Page 25: Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649eea5503460f94bfbbb9/html5/thumbnails/25.jpg)
Review: AboutMe Part2Modify your app to include your
timetable with start and end times for each class.
Include code to properly align the data into 2 columns with the courses left aligned and the times right aligned.
Use the format() method for this.