-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaIntro4.java
More file actions
26 lines (22 loc) · 1.01 KB
/
JavaIntro4.java
File metadata and controls
26 lines (22 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//Project Name: Spectrum 4th Program
public class JavaIntro4 {
/*add 4 to the parameter sent to the method and return the result*/
public static double addFour(double num){ // the variable type before the method name is what type will be returned
return num + 4; //return is the keyword that tells java to end the method and send the value
}
/*if the boolean named bol is true than print out the double named num*/
public static void ifTruePrint(boolean bol, double num){ //void means the method won't return any value
if (bol){
System.out.println(num);
}
} //this method doesn't return a value
public static void main(String[] args) { //This line lets Java know what to run when you click execute below
boolean b1 = true;
boolean b2 = false;
double x = 10;
double y = 20;
System.out.println(addFour(x));
ifTruePrint(b1, x); //if b1 is true print x
ifTruePrint(!b1, y); //if b1 is not true print y
}
}