Java Lab 14
Java Lab 14
Create a new Java file (empty Java file), save it to your H: drive, call it lab14
Insert the following code to set up your program:
Be sure to copy the test text files to the location where you saved your Java file
import java.io.*;
100pt:
A method called multiplyTwo() that takes two integers and multiplies them together, returning
the result as an integer.
o Example: multiplyTwo(2,10) returns 20.
A method called largerString() that takes two Strings as arguments, and returns the longer of
the two Strings.
o Example: largerString(“Hello”,”one”) returns “Hello”
A method called writeToFile() that takes two arguments. Both arguments are Strings. The first
argument is a piece of text, the second argument is the name of a text file to store that text. The
method will take the first argument and store it in the filename given in the second argument.
There is no data returned from the method. (use void)
o Example: writeToFile(“Hello World”, “output.txt”) writes the String “Hello World” to the
text file “output.txt”.
Notes:
Creating a method:
Calling a method:
printInt(10);