Skip to content

Commit 792de99

Browse files
committed
added method demo
1 parent ce03ee9 commit 792de99

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

ch04/HelloMethod.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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!!!!!!!!!!!!!!!!!!!!!!! " + cat);
34+
System.out.println("Is a person? " + isAPerson);
35+
System.out.println("First Number is " + firstNumber);
36+
System.out.println("Second Number is " + secondNumber);
37+
System.out.println("total is " + (firstNumber + secondNumber));
38+
}
39+
40+
41+
}

0 commit comments

Comments
 (0)