Description
- Write a Java method that prints a list of characters using the following header:
public static void printChars (char ch1, char ch2, int numPerLine)
This method prints chars between ch1 and ch2 (inclusive); the number of chars per-line is specified by int variable numPerLine. Then write a test Java program that prints characters from 1 to Z (uppercase), ten chars per line. Consecutive characters should be separated by exactly one space.
- Write a method that displays an n-by-n matrix of integers, where only integers 0, 1 and 2 are allowed (and generated with equal probabilities).
Use the following header for your method:
public static void printMatrix(int n)
Each matrix element is 0, 1 or 2; and is generated randomly. Then write a test Java program that prompts the user to enter n and displays a random n-by-nmatrix per above, if n is in the desired range. Valid matrix sizes are values of n between 1 and 20; the user should be notified that his or her size is out of range otherwise.
Your output should show five test runs for the following values of n: 3, 5, 7, 15, 25.
- Write a Java program that reads an unspecified number of scores (positive integers) and determines how many of those scores are strictly above the arithmetic average, and how many scores are strictly below the average. The user entering a negative number signifies the end of the input (the value of that negative number does not count towards the average). Assume all scores are integers between 0 and 100; and make sure the number of scores the user enters cannot exceed 100.
Show output of running your code on three sequences of scores of your choosing; as well as the following two specific sequences:
- 100, 0, 50, 99, 1, 98, 2, 50, 97, 3, -1
- 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 75, 75, -100
- Write a Java program that generates 100 random int’s between 0 and 9 (inclusive), and displays the count for each of those ten values (For example: eight 0s, ten 1s, fifteen 2s, nine 3s, etc.; the total count should obviously add up to 100.)
A small hint: Use arrays in a smart way for this problem!
- Write a method that takes a list of single-digit integers as its input and returns a new array in which the duplicate values in the original list are removed (i.e., only one copy of each distinct value occurring in the original array is kept). For example, if the user has entered the following list of values: 1 2 3 2 1 6 3 4 5 2, then the output (the distinct values in that list) are: 1 2 3 6 4
Write a test program that reads in anywhere between 2 and 25 nonnegative integers, invokes your method, and displays an array of distinct numbers from the original user input, with consecutive numbers separated by exactly one space. Include in the submission of your output five sample runs of your program for lists of length 5, 10, 15, 20 and 25. The end of the user-entered list is marked by entering a negative value (which does not count towards the distinct elements in the list or the list’s length, and is purely used as the end-of-input signal).