Skip to content

Commit 2f699ae

Browse files
committed
Added method demo
1 parent ce03ee9 commit 2f699ae

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎ch04/HelloMethod.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
public class HelloMethod
2+
{
3+
public static void main(String[] args)
4+
{
5+
String firstName = "Fred";
6+
String secondName = "Wilma";
7+
String lastName = "Flintstone";
8+
9+
printHelloWorld(firstName, lastName);
10+
printHelloWorld(secondName, lastName);
11+
12+
int firstNum = 5;
13+
int secondNum = 10;
14+
printOhNo(firstName, firstNum, secondNum, false);
15+
16+
printNumberNoSign(5);
17+
printNumberNoSign(-5);
18+
}
19+
20+
public static void printNumberNoSign (int number)
21+
{
22+
int positiveNumber = Math.abs(number);
23+
System.out.println("The number is " + positiveNumber);
24+
}
25+
26+
public static void printHelloWorld(String fName, String lName)
27+
{
28+
System.out.println("Hello, World " + fName + " " + lName + ".");
29+
}
30+
31+
public static void printOhNo(String cat, int firstNumber, int secondNumber, boolean isAPerson)
32+
{
33+
System.out.println("Oh no!");
34+
System.out.println("First Number is " + firstNumber);
35+
System.out.println("Second Number is " + secondNumber);
36+
System.out.println("Total is " + (firstNumber + secondNumber));
37+
}
38+
}

0 commit comments

Comments
 (0)