Menu

Java Thank Public Class Q5 Public Static Void Main String Args Boolean Test New Boolean 8 Q43859037

In JAVA,Thank you!For this section, many methods are given. They however contain errors. Some errors are syntax error while others are logical//method that determines if the number x is prime public static boolean isPrime(int x) { boolean prime = true; if(x ){ primeYou need to correct the code above until all tests pass successfully and that you get the following output message: test 0 pa

public class Q5{ public static void main(String[] args){ boolean[] test = new boolean[8]; //test for isPrime test[0] = (isPrime(0) == false); test[1] = (isPrime(2) == true); test[2] = (isPrime(7) == true); test[3] = (isPrime(15) == false); test[4] = (getFibonacci(1) == 1); test[5] = (getFibonacci(3) == 2); test[6] = (getFibonacci(5) == 5); test[7] = (getFibonacci(8) == 21); boolean testFlag=true; for (int i = 0; i < test.length; i++){ if(test[i]){ System.out.println(“test ” + i + ” passed”); } else { System.out.println(“test ” + i + ” failed”); testFlag = false; } } if(testFlag ){ System.out.println(“All tests are successful”); } else { System.out.println(“Not all tests are successful”); } } //method that determines if the number x is prime public static boolean isPrime(int x){ boolean prime = true; if(x < ){ prime = ; } if(x== ){ prime = ; } int i = 2; while(prime && x < i){ if(x % i == 0){ prime = false; } i++; } return prime; } //returns the fibonacci number at the position in parameter public static int getFibonacci(int position) { int num = 0; int num2 = 1; int fibonacci = 0; if (position == ) { fibonacci = 0; } else if (position == 1) { fibonacci = ; } else { for (int i = 2; ; ) { fibonacci = ; num = num2; num2 = fibonacci; } } return num; }}For this section, many methods are given. They however contain errors. Some errors are syntax error while others are logical error. The main method contains test that will execute the two other methods and verify if they work properly. The method is Prime checks if the number received as an argument is a prime number. A prime number is a number bigger then 1 that can only be divided by 1 or itself. The Fibonacci method takes a number as argument and returns the value at this position in the Fibonacci series. In the Fibonacci series, each number is the sum of the two preceding position in the series. The position O has the value 0 and the position 1 has the value 1. This table describes the series: position 01234 5 6 7 8 9 Value 112 3 5 8 1321134 public class 03 public static void main(String[] args) { booleant 1 test = new boolean[811 // test for iserine test[0] – (isrine(0) — false); test.[1] = ( i rino(2) == D.TUR); test2) – (isrinc(7) — true); test[3] – (iPrine (15) — false) test[4] test.[5] test161 test[7] – (getr’ibonacci(-) — -) = (get.Fibonacci (3) == 2) – (getVibonacci(5) — 5): – (getfibonacel(B) — 2157 boolean LA.Pag-YOR; for (int i = 0; i < test.length; i++){ if(test ) System.out.println(“test ‘ + i + ‘passed’); } else { System.out.println(‘LART + 1 + failed testlag – false; System.out.println(‘ALL test are sucessful”): } else { System.out.println(‘Not all tests are successful”} //method that determines if the number x is prime public static boolean isPrime(int x) { boolean prime = true; if(x ){ prime = ; if(x== ) { prime = ; int i = 2; while(prime && x < i) { if (x % i == 0){ prime = false; i++; return prime; //returns the fibonacci number at the position in parameter public static int getFibonacci(int position) { int num = 0; int num2 = 1; int fibonacci = 0; if (position == ) { fibonacci = 0; } else if (position == 1) { fibonacci = ; } else { for (int i = 2;;) { fibonacci = ; num = num2; num2 = fibonacci; return num; You need to correct the code above until all tests pass successfully and that you get the following output message: test 0 passed test 1 passed test 2 passed test 3 passed test 4 passed test 5 passed test 6 passed test 7 passed All tests are successful Show transcribed image text For this section, many methods are given. They however contain errors. Some errors are syntax error while others are logical error. The main method contains test that will execute the two other methods and verify if they work properly. The method is Prime checks if the number received as an argument is a prime number. A prime number is a number bigger then 1 that can only be divided by 1 or itself. The Fibonacci method takes a number as argument and returns the value at this position in the Fibonacci series. In the Fibonacci series, each number is the sum of the two preceding position in the series. The position O has the value 0 and the position 1 has the value 1. This table describes the series: position 01234 5 6 7 8 9 Value 112 3 5 8 1321134 public class 03 public static void main(String[] args) { booleant 1 test = new boolean[811 // test for iserine test[0] – (isrine(0) — false); test.[1] = ( i rino(2) == D.TUR); test2) – (isrinc(7) — true); test[3] – (iPrine (15) — false) test[4] test.[5] test161 test[7] – (getr’ibonacci(-) — -) = (get.Fibonacci (3) == 2) – (getVibonacci(5) — 5): – (getfibonacel(B) — 2157 boolean LA.Pag-YOR; for (int i = 0; i

Expert Answer


Answer to In JAVA,Thank you! public class Q5{ public static void main(String[] args){ boolean[] test = new boolean[8]; //test …

OR