1. Name the Four (Eight) Primitive Types in Java

Total Page:16

File Type:pdf, Size:1020Kb

1. Name the Four (Eight) Primitive Types in Java

Anna Chesson C-212 Homework 6

1. Name the four (eight) primitive types in Java : int, short, long, double, float, boolean, char, byte

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]

Recommended publications