-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtab3.html
More file actions
42 lines (32 loc) · 2.3 KB
/
Copy pathtab3.html
File metadata and controls
42 lines (32 loc) · 2.3 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
<!DOCTYPE html>
<html>
<head>
<title>project</title>
<meta charset="utf-8">
<link rel = "stylesheet" href="style.css">
</head>
<body>
<div class="topnav">
<a href="aclhack.html"> Home </a>
<a href="tab1.html">Beginner</a>
<a href="tab2.html">Intermediate</a>
<a href="tab3.html">Beyond Scratch</a>
<a href="AboutUs.html">About Us</a>
</div>
<h1> Beyond Scratch </h1>
<table style = "border: 3px solid white;">
<tr>
<th>Java</th>
<th>Explanation</th>
</tr>
<tr>
<td><img src = "hackathoncode1.png"></td>
<td>
When you get into more advanced Java, you might want to create your own function. There are many built-in functions in Java, such as .contains and .length. However, if your program requires you to reuse the same block of code over and over again, instead of making your code longer by copying over the code each time, you can create a function. You can apply this function throughout your code. <br>
On the left we see an example of a function. First, we use Scanner to take input from the user. This input is stored in scan and goes to another variable, <strong>input</strong> as a String. Now, our function. Our function is designed to count the amount of the letter “e” in our input. To set up a function, we start out with public static. Then, we add the type of data we want as the output. In this case, we want a count, so we write public static <strong>int</strong>. Following this is our function name, countOfE. Finally, in parenthesis, we put the input we are taking into the function. In this case, we are taking one String, and we can name it anything, such as <strong>word</strong>. We use this variable name inside function code.<br>
Inside the function is the code we would like to use in the function. We use an if statement inside a for loop to count the amount of e’s. Finally, we must return a value. This will output the final value in our main code. We go back to the main code and see we are printing our input inside our written function. This will return a number, the amount of e’s in the given user input.<br>
</td>
</tr>
</table>
</body>
</html>