Consider the following code: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Now what? What is the first executable statement? The declaration is first Record the variables and their value Then step through the statements Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill First step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Second step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 2 5 Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Third step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 Assume input line is: 7 4 -6 Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Fourth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Fifth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2018 - Curt Hill
Copyright © 2004-2018 - Curt Hill Sixth-Eighth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2018 - Curt Hill