Download presentation
Presentation is loading. Please wait.
Published byJeremy Rose Modified over 9 years ago
1
Indentation & Readability
2
What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
3
What does this program do? public class Hello2{public static void main(String[] args){System.out.println( “Welcome.");System.out.println();int i=12;System.out.println("i is equal to "); System.out.println(i);System.out.println("Bye."); }}
4
Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{public static void main(String[] args){System.out.println("Welcome.") ;System.out.println();int i=12;System.out.println( "i is equal to" );System.out.println(i);System.out.println ("Bye.");}} Stream of Consciousness
5
Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome."); System.out.println();int i=12; System.out.println( "i is equal to" );System.out.println(i);System.out.println ("Bye.");} } Random Indentation
6
Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome." ); System.out.println(); int i=12; System.out.println( "i is equal to" );System.out.println(i); System.out.println("Bye." );}} Artistic / Poet
7
Which do you prefer (to see on an exam)? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); } public class Hello2{ public static void main( String[] args) { System.out.println( "Welcome." ); System.out.println(); int i=12; System.out.println( "i is equal to" );System.out.println(i); System.out.println("Bye." );}} Artistic / Poet
8
What’s the title of this poem?
9
Comment rules 1.Comments are required (by me)! – You may use the problem description as the basis for your comments. 2.Comments should be placed before (not after) the code they describe.
10
Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces.
11
Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
12
Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
13
Indentation rules 1.All lines within the same block should line up on the left. 2.All lines following { should be indented +4 spaces. 3.All lines including and then following } should be unindented -4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
14
Indentation rules (one more time) Start of block lines up with end. All lines in block should be indented +4 spaces. public class Hello { }
15
Indentation rules (one more time) Start of block lines up with end. All lines in block should be indented +4 spaces. public class Hello { public static void main ( String[] args ) { }
16
Indentation rules (one more time) All lines in block should be indented +4 spaces. public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
17
Alternate placement of {…} public class Hello { public static void main ( String[] args ) { //display initial message System.out.println( "Welcome." ); System.out.println( ); //initialize i and output its value int i = 12; System.out.println( "i is equal to " ); System.out.println( i ); //display final message System.out.println( "Bye." ); }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.