Java Reference
In-Depth Information
e. Write a loop that finds the minimum element in the array.
f. Randomly generate an index and display the element of this index in the array.
g. Use an array initializer to create another array with the initial values 3.5 , 5.5 ,
4.52 , and 5.6 .
6.9
What happens when your program attempts to access an array element with an
invalid index?
6.10
Identify and fix the errors in the following code:
1
public class Test {
2
public static void main(String[] args) {
3
double [ 100 ] r;
4
5 for ( int i = 0 ; i < r.length(); i++);
6 r(i) = Math.random * 100 ;
7 }
8 }
6.11
What is the output of the following code?
1 public class Test {
2 public static void main(String[] args) {
3 int list[] = { 1 , 2 , 3 , 4 , 5 , 6 };
4 for ( int i = 1 ; i < list.length; i++)
5 list[i] = list[i - 1 ];
6
7 for ( int i = 0 ; i < list.length; i++)
8 System.out.print(list[i] + " " );
9 }
10 }
6.3 Case Study: Lotto Numbers
The problem is to write a program that checks if all the input numbers cover 1 to 99 .
Key
Point
Each ticket for the Pick-10 lotto has 10 unique numbers ranging from 1 to 99 . Suppose you
buy a lot of tickets and like to have them cover all numbers from 1 to 99 . Write a program that
reads the ticket numbers from a file and checks whether all numbers are covered. Assume the
last number in the file is 0 . Suppose the file contains the numbers
80 3 87 62 30 90 10 21 46 27
12 40 83 9 39 88 95 59 20 37
80 40 87 67 31 90 11 24 56 77
11 48 51 42 8 74 1 41 36 53
52 82 16 72 19 70 44 56 29 33
54 64 99 14 23 22 94 79 55 2
60 86 34 4 31 63 84 89 7 78
43 93 97 45 25 38 28 26 85 49
47 65 57 67 73 69 32 71 24 66
92 98 96 77 6 75 17 61 58 13
35 81 18 15 5 68 91 50 76
0
VideoNote
Lotto numbers
Your program should display
The tickets cover all numbers
Suppose the file contains the numbers
11 48 51 42 8 74 1 41 36 53
52 82 16 72 19 70 44 56 29 33
0
 
 
Search WWH ::




Custom Search