Download presentation
Presentation is loading. Please wait.
Published byElinor Hunt Modified over 9 years ago
1
Java Syntax and Output Java Part 3
2
public class CompSci { } All Java programs start with a class.
3
public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } } OUTPUT Comp Sci!
4
public class CompSci { //open brace public static void main(String[] args) { System.out.println("Comp Sci!"); } } //close brace Braces – You gotta have ‘em! Every class and every method must have a { and a }.
5
© 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 ( ; ).
6
Never put a ; before an open { brace ;{ //illegal }; //legal
7
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.
8
Java Output System.out frequently used methods NameUse 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
9
System.out.print( " compsci"); referencecommand / method OUTPUT compsci
10
System.out.print("compsci"); OUTPUT compscicompsci
11
System.out.println("compsci"); OUTPUT compsci
12
System.out.println("compsci"); OUTPUTcompsci
13
System.out.println("c\tompsci " ); \nnewline \ttab \rcarriage return \bbackspace OUTPUT c ompsci
14
System.out.println("com\tpsci " ); OUTPUT com psci \nnewline \ttab \rcarriage return \bbackspace
15
System.out.println("comp\nsci"); OUTPUT comp sci \nnewline \ttab \rcarriage return \bbackspace
16
\\outs \ \"outs " \’outs ’ System.out.println( " \\compsci\ " / " ); OUTPUT \compsci"/
17
\\outs \ \"outs " \’outs ’ System.out.println("\\'comp\'sci\'/"); OUTPUT \'comp'sci'/
18
© A+ Computer Science - www.apluscompsci.com Escape Sequences frequently used combinations NameUse \ttabs over five spaces \nmoves to front of next line \bdeletes previous character \rmoves to front of current line \\nets one backslash \ \"nets one double quote " \’nets one single quote ’
19
© A+ Computer Science - www.apluscompsci.com //single-line comments /* */block comments //this line prints stuff on the screen System.out.println("stuff");
20
Review: AboutMe Part1 Create 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.
21
//single-line comments /* */block comments /* this line prints stuff on the screen */ System.out.println("stuff");
22
© A+ Computer Science - www.apluscompsci.com System.out.printf("%s","compsci\n"); OUTPUT compsci
23
format()
24
© A+ Computer Science - www.apluscompsci.com
25
Review: AboutMe Part2 Modify 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.