Download presentation
Presentation is loading. Please wait.
1
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 © Curt Hill
2
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 © Curt Hill
3
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 ? Copyright © Curt Hill
4
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 ? Copyright © Curt Hill
5
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 ? Assume input line is: Copyright © Curt Hill
6
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 ? Copyright © Curt Hill
7
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 ? Copyright © Curt Hill
8
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 ? Copyright © Curt Hill
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.