Java Reference
In-Depth Information
System.out.println("strList: " + strList);
System.out.println("intList: " + intList);
}
}
PROGRAMMING EXERCISES
1. Write a Java program that declares an array alpha of 50 elements of
type double . Initialize the array so that the first 25 elements are equal to the
square of the index variable, and the last 25 elements are equal to three times the
index variable. Output the array so that 10 elements per line are printed.
2. Write a Java method, smallestIndex , that takes as its parameters an int
array and its size, and returns the index of the (first occurrence of the)
smallest element in the array. Also, write a program to test your method.
3. Write a Java method, lastLargestIndex , that takes as parameters an int
array and its size and returns the index of the last occurrence of the largest
element in the array. Also, write a program to test your method.
4. Write a program that reads a file consisting of students' test scores in the range
0-200 . It should then determine the number of students having scores in each of
the following ranges: 0-24 , 25-49 , 50-74 , 75-99 , 100-124 , 125-149 , 150-174 ,
and 175-200 . Output the score ranges and the number of students. Run your
program with the following input data: 76 , 89 , 150 , 135 , 200 , 76 , 12 , 100 , 150 ,
28 , 178 , 189 , 167 , 200 , 175 , 150 , 87 , 99 , 129 , 149 , 176 , 200 , 87 , 35 , 157 , 189 .
5. Write a program that prompts the user to input a string and then outputs the string
in uppercase letters. (Use an array of characters [or char ] to store the string.)
6. The history teacher at your school needs help grading a True/False test. The
students' IDs and test answers are stored in a file. The first entry in the file
contains the answers to the test in the following form:
TFFTFFTTTTFFTFTFTFTT
Every other entry in the file is the student's ID, followed by a blank,
followed by the student's response. For example, the entry:
ABC54301 TFTFTFTT TFTFTFFTTFT
indicates that the student's ID is ABC54301 and the answer to question 1 is True,
the answer to question 2 is False, and so on. This student did not answer
question 9. The exam has 20 questions, and the class has more than 150 students.
Each correct answer is awarded two points, each wrong answer gets -1 point,
and no answer gets 0 points. Write a program that processes the test data. The
output should be the student's ID, followed by the answers, followed by the test
score, followed by the test grade. Assume the following grade scale: 90% - 100% ,
A ; 80% - 89.99% , B ; 70% - 79.99% , C ; 60% - 69.99% , D ;and 0% - 59.99% , F .
 
Search WWH ::




Custom Search