indentation & readability. what does this program do? public class hello { public static void...

Post on 17-Jan-2016

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Indentation & Readability

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." );

}

}

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.");}}

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

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

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

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

What’s the title of this poem?

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.

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.

Indentation rules1. 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." );

}

}

Indentation rules1. 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." );

}

}

Indentation rules1. 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." );

}

}

Indentation rules (one more time)• Start of block lines up with

end.

• All lines in block should be indented +4 spaces.

public class Hello {

}

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 ) {

}

}

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." );

}

}

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." ); }

}

top related