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

Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
Write a Java application that accepts a bar code as a command line parameter and prints...
Write a Java application that accepts a bar code as a command line parameter and prints out the ZIP code. Assume that the bar code uses the symbols "|" and ":" for the long and short bars, respectively. Provide warnings on errors in the bar code specifying what exactly is wrong. The bar code input should be in the format specified in Problem 1, including the pair of the full bars at the beginning and at the end. Important: The...
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
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT