Logout
Scope Explanation Program
ScopeMain.java
/Users/adelaide/Public/Netbeans - All JSR Projects/Scope Project/src/scopepackage/ScopeMain.java |
1
2
3
4
5
6 package scopepackage;
7
8
9
10 @author
11
12 public class ScopeMain {
13
14 static double f = 8.9;
15 public static void main(String[] args) {
16 System.out.println("Our Program Showing Scope Issues");
17 System.out.println("---------------------------------");
18 System.out.println("");
19
20 scopeMethodThatWorks();
21 double g = 7.3;
22
23 scopeMethodWithProblem();
24
25 double a = 44.4;
26 double b = 66.7;
27
28 methodShowingSopeAndPrameters(a, b);
29
30 methodWithMultipleBlocks(12, 2);
31
32
33
34 }
35
36
37
38 private static void scopeMethodThatWorks(){
39 double d = 3.2;
40 double e = 4.3;
41 System.out.println("d + e + f = " + (d + e + f));
42
43 }
44
45 private static void scopeMethodWithProblem(){
46 double h = 34.2;
47 double i = 32.2;
48 System.out.println("h + i + g = " + (h + i + g));
49
50 }
51
52 private static void methodShowingSopeAndPrameters(double aIn, double bIn){
53 double c = 234.2;
54 double d = 4545;
55 System.out.println("a + b + c + d = " + (aIn + bIn + c + d));
56 System.out.println("a + b + c + d = " + (aIn + bIn + c + d + f));
57
58 }
59
60
61
62
63
64 public static void methodWithMultipleBlocks(int a, int b){
65
66
67 if(a < 10){
68 String sentence1 = "stringWithinFirstBlock";
69 for(int i = 0; i < a; i++){
70 System.out.println("If the first number taken in ia a reasonably small value,"
71 + "we will print this line and " + sentence1 + "that many (" + a + ")times.");
72 }
73
74 }else if(b < 3){
75 for(int i = 0; i < b; i++){
76 System.out.println("If the second number taken in ia less than 3,"
77 + "we will print this line and " + sentence1 + "that many (" + b + ")times.");
78
79
80
81 }
82
83 }else{
84 System.out.println("Both numbers taken in were bigger than this method can handle.");
85
86 }
87
88 }
89
90
91
92 }
93
94