JAVA QUESTIONS:
1. Write a method called arrayTimesFive
2. Declare an array of Strings named plants and assign it the values rose, jasmine, daffodil
3. Write 5-6 lines of code to open a PrintWriter and write out the contents of the plants array into a text file named plants.txt
import java.io.FileNotFoundException; import java.io.PrintWriter; public class JavaQuestions { // 1 public static void arrayTimesFive(double[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] *= 5; } } public static void main(String[] args) throws FileNotFoundException { // 2 String[] plants = {"rose", "jasmine", "daffodil"}; // 3 PrintWriter pw = new PrintWriter("plants.txt"); for (int i = 0; i < plants.length; i++) { pw.println(plants[i]); } pw.close(); } }
Get Answers For Free
Most questions answered within 1 hours.