Repository navigation
Expand file tree
/
Copy pathMethodsLec.java
More file actions
73 lines (61 loc) · 1.96 KB
/
Copy pathMethodsLec.java
File metadata and controls
73 lines (61 loc) · 1.96 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class MethodsLec {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
validateCurrency(input);
countdownRecursion(10);
countdown();
System.out.println(sayHello("Fernando", "Mendoza"));
System.out.println(sayHello());
System.out.println("sum() " + sum(1, 2));
System.out.println("decimal sum() " + sum(3.4, 6.7));
System.out.println("sayHello() = " + sayHello("Douglas"));
System.out.println();
}
public static String sayHello(){
return "Hello world";
}
public static String sayHello(String name){
return "Hello " + name;
}
public static String sayHello(String firstName, String lastName){
return "Hello " + firstName + " " + lastName;
}
public static int sum(int num1, int num2){
return num1 + num2;
}
public static double sum(double num1, double num2){
return num1 + num2;
}
// counting from 5 to 1 using a loop
public static void countdown(){
for (byte x = 5; x >= 0 ;x--){
System.out.println("for loop = " + x);
}
}
// n a variable number
public static void countdownRecursion(int n){
System.out.println("recursion = " + n);
// how to stop
if(n < 1){
return;
}
// how to proceed
n = n - 1;
// how to try again with new data
countdownRecursion(n);
}
// that only looks for $
public static void validateCurrency(Scanner scan){
System.out.println("Give me an amount: ");
String amount = scan.nextLine();
// how to stop
if(amount.startsWith("$")){
System.out.println("It's valid money format");
return;
}
// how to proceed, how to run process again?
System.out.println("Invalid money format, try again");
validateCurrency(scan);
}
}