![1. Name the Four (Eight) Primitive Types in Java](https://data.docslib.org/img/3a60ab92a6e30910dab9bd827208bcff-1.webp)
<p>Anna Chesson C-212 Homework 6</p><p>1. Name the four (eight) primitive types in Java : int, short, long, double, float, boolean, char, byte</p><p>2. The output of this program would be false. The reason is because the operator “==” performs a check and returns a Boolean value. If you call it with two of the same arguments (tomato tomato) it will return false also because == compares two objects. The strings tomato and tomato look the same but they are not actually the same object. By using the .equals method you could check if they are equal to the eye. 3. There is only 1, private char[][] board; 4. There are 3 static variables, 2 instance methods, and 1 static method. 5. The program does not compile because math random returns a decimal (double) value, and thus math floor operating on the decimal value also returns a double, and in the instance variables of diceOne and diceTwo we defined them to be ints. 6. Math.floor always returns a double 7. (int)(Math.random() * 100) – 50. This converts the math.random value to an integer 8. public boolean sorted(int[] arr) { for(int i = 0; i < arr.length – 1; i++) { if(i = arr.length – 1) { return true; } if(arr[i]<arr[i+1]) {} else { return false;} } } 9. Yes, you can use the java.util.Scanner to eliminate the excess code here. One side effect of using the written code would be the worry about the possibility of an io exception 10. The program can only take numbers from 1 to 12 11. To modify the code to have more informative error messages you could put in a “throws Exception” where the program will output System.out.println(“Please enter a number 1 through 12”); 12. The program defines a class PrimeFactorsTest that within uses a bufferreader to read user inputs from the console. The program then uses this number in several static methods, isPrime and printPrimeFactors. Both these methods are brute force methods. The program then calls a main method that prints out the prime factors for each number the user enters until they enter -1 (system puts this out as a prompt in the beginning so the user knows this) using a while loop. 13. isPrime is inefficient because you would never have to check and numbers to be factors above the given numbers square root to know if it were prime. That’s a mathematical property/fact.</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages1 Page
-
File Size-