0
. Note that if a number occurs more than one time, the plural
word "times" is used in the output. You must use an array in this problem,
no other container can be used, e.g., ArrayList
.
ch7pr3.java
.java ch7pr3
) user provides input:
Enter the integers between 1 and 100:
2 5 6 4 3 23 43 2 0
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 1 time
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time
public static int solveQuadratic(double[] eqn, double[] roots);
ax2 + bx + c = 0
are passed to the array
eqn
and the real roots are stored in roots. The method returns
the number of real roots. Write a program that prompts the user to enter
values for a
, b
, and c
and displays
the number of real roots and all real roots.
ch7pr25.java
.java ch7pr25
) user provides input:
Enter values for a, b, and c of ax^2 + bx + c = 0:
5.4 6.2 1.5
5.400000x^2 + 6.200000x + 1.500000 = 0 has 2 real roots.
Real root 0: x = -0.346515
Real root 1: x = -0.801633
java ch7pr25
) user provides input:
Enter values for a, b, and c of ax^2 + bx + c = 0:
5 2 1
5.000000x^2 + 2.000000x + 1.000000 = 0 has 0 real roots.
java ch7pr25
) user provides input:
Enter values for a, b, and c of ax^2 + bx + c = 0:
-3 -24 -48
-3.000000x^2 + -24.000000x + -48.000000 = 0 has 1 real roots.
Real root 0: x = -4.000000
list1
and list2
are
identical if they have the same contents. Write a method that returns
true
if list1
and list2
are
identical, using the following header:
public static boolean equals(int[] list1, int[] list2);
Array.sort
, but at
least consider trying to think of how to solve it without that function.
ch7pr27.java
.java ch7pr27
) user provides input:
Enter list1: 5 2 5 6 6 1
Enter list2: 5 5 2 6 1 6
Two lists are identical
java ch7pr27
) user provides input:
Enter list1: 5 5 5 6 6 1
Enter list2: 5 2 5 6 1 6
Two lists are not identical
public static int[] merge(int[] list1, int[] list2);
list1.length + list2.length
comparisons. Write a test program
that prompts the user to enter two sorted lists and displays the merged
list. Note that the first number in the input indicates the number of the
elements in the list. This number is not part of the list.
You cannot use Arrays.sort()
.
ch7pr31.java
.java ch7pr31
) user provides input:
Enter list1: 5 1 5 16 61 111
Enter list2: 4 2 4 5 6
The merged list is 1 2 4 5 5 6 16 61 111
// Add any words you wish in this array
String[] words = {"write", "that", "program"};
ch7pr35.java
.java ch7pr35
) user provides input:
(Guess) Enter a letter in word ******* > p
(Guess) Enter a letter in word p****** > r
(Guess) Enter a letter in word pr**r** > p
p is already in the word
(Guess) Enter a letter in word pr**r** > o
(Guess) Enter a letter in word pro*r** > g
(Guess) Enter a letter in word progr** > n
n is not in the word
(Guess) Enter a letter in word progr** > m
(Guess) Enter a letter in word progr*m > a
The word is program. You missed 1 time
Do you want to guess another word? Enter y or n> n