Question

In: Computer Science

with java code write The method prints a meaningful title with your name as the author....

with java code

write The method prints a meaningful title with your name as the author. The method then generates THREE random numbers 0 - 4 and reports how many of the numbers are the same.

2-Use a loop to repeat 10 times.

the output should be like this

Title title title by Your Name
4, 3, 4 two are the same
4, 0, 0 two are the same
. . . 
2, 0, 4 none are the same
4, 4, 4 three are the same
2, 3, 3 two are the same

Solutions

Expert Solution

Code:

import java.util.Random;
public class Code{
//myLoop is a method
static void myLoop(){
System.out.println("Looper and equality checker by Soligt"); //title with name
int high = 5, a, b, c, i;//variable declaration
Random random = new Random();//random class instance
//the following loop iterates for 10 times from i=0 to i=9
for(i=0; i<10; i++){
a = random.nextInt(high);//generates a random number in the range of 0 to high=5
b = random.nextInt(high);//generates another random number in the range of 0 to high=5
c = random.nextInt(high);//generates another random number in the range of 0 to high=5
//checks if all three random number are equal and prints the corresponding statement
if(a == b && a == c){
System.out.printf("%d, %d, %d three are the same\n", a, b, c);
}
//checks if any two random number are equal and prints the corresponding statement
else if((a == b && a != c) || (a == c && a != b) || (b == c && b != a)){
System.out.printf("%d, %d, %d two are the same\n", a, b, c);
}
//if all the above conditions fail, the following in printed
else{
System.out.printf("%d, %d, %d none are the same\n", a, b, c);
}
}
}
//main method calls the myLoop() method
public static void main(String[]args){
myLoop();
}
}

Code in the image:

Please refer to the following image for indentation of the code.

Output:


Related Solutions

Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and then increments the number of seconds. The counter will start at 00:00 and each time the number of seconds reaches 60, minutes will be incremented. You will not need to implement hours or a sleep function, but if minutes or seconds is less than 10, make sure a leading zero is put to the left of the number. For example, 60 seconds:...
Java Write a method that reads a text file and prints out the number of words...
Java Write a method that reads a text file and prints out the number of words at the end of each line
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
Write a Java method called printAvg that takes in two floating point numbers and prints out...
Write a Java method called printAvg that takes in two floating point numbers and prints out the average of them.
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write an application that includes a constructor, user input, and operators.
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
Write this code in java and don't forget to comment every step. Write a method which...
Write this code in java and don't forget to comment every step. Write a method which asks a baker how hot their water is, and prints out whether it is OK to make bread with the water. If the water is at or above 110F, your method should print "Too Warm." If the water is below 90.5F, print "Too Cold." If it is in between, print "Just right to bake!" For example, if the user inputs the number 100.5, the...
Just that method --> Java code Write a method “int sumPos(List aList)” to calculate the sum...
Just that method --> Java code Write a method “int sumPos(List aList)” to calculate the sum of positive integers in an ADT List aList of integers using ADT List operations. ADT List operations: isEmpty(), size(), add(index, item), remove(index), get(index), and removeAll(). You should not assume how an ADT List is implemented. Using array indexing, head/tail references, or any operation not defined in ADT List is not allowed.
in java code In the class Hw2, write a method removeDuplicates that given a sorted array,...
in java code In the class Hw2, write a method removeDuplicates that given a sorted array, (1) removes the duplicates so that each distinct element appears exactly once in the sorted order at beginning of the original array, and (2) returns the number of distinct elements in the array. The following is the header of the method: public static int removeDuplicates(int[ ] A) For example, on input A=0, 0, 1, 1, 1, 2, 2, 3, 3, 4, your method should:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT