Hi I was given help with the problem with the java programming   Generate a random number in java between 1 and 100. Then prompt the user for a number between 1 and 4. Next, the program will determine if the number entered by the user is a factor of the random number.   I was able to code up to the point of where I got an error. I'm not sure where i'm off. I tried re-doing my code but I get the same problem with my opening and closing bracket.  Here's the code thus far: import java.util.Scanner; public class ModuleP3 { public static void main(String[] args) {Scanner input = new Scanner(System.in);int num1 = (int)(Math.random()*100+1);System.out.println("Enter the number between 1 and 4: ");int userinput = input.nextInt();for(int i=1;i<=4;i++){ if(i==userinput){if(num1%userinput==0){System.out.println("The given input" + userinput + "is a factor of generated random number" + num1);}else{System.out.println("The generated random number is:" + num1); System.out.println("The given input " + userinput + "is not a factor of a generated random number" + num1);} }

Question

Hi I was given help with the problem with the java programming

 

Generate a random number in java between 1 and 100. Then prompt the user for a number between 1 and 4. Next, the program will determine if the number entered by the user is a factor of the random number.

 

I was able to code up to the point of where I got an error. I'm not sure where i'm off. I tried re-doing my code but I get the same problem with my opening and closing bracket. 

Here's the code thus far:

import java.util.Scanner;

public class ModuleP3
{

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int num1 = (int)(Math.random()*100+1);

System.out.println("Enter the number between 1 and 4: ");

int userinput = input.nextInt();

for(int i=1;i<=4;i++)
{

if(i==userinput)

{

if(num1%userinput==0)
{

System.out.println("The given input" + userinput + "is a factor of generated random number" + num1);

}
else
{

System.out.println("The generated random number is:" + num1);

System.out.println("The given input " + userinput + "is not a factor of a generated random number" + num1);



}



}

 

 

 

Expert Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you

Q: What is the difference between Computer Science and Computer Engineering?

A: Difference between computer science and computer engineeringBoth computer science and engineering be...

Q: I have a bit of code that is intended to read a file ("students.txt") and calculate the average, hig...

A: Description:The following program is to print the highest, lowest, and average of test scores by rea...

Q: Create a new file in c++ and save it as lab11_XYZ.cpp (replace XYZ with your initials). Create ANOTH...

A: Program Instructions:In the header file, create a temporary variable temp of the data type of each v...

Q: For this program you need to use Eclipse. Carefully read the instructions and write a program that r...

A: The program has the following algorithm: Step 1: Create object for “Scanner” class to read the user ...

Q: A common problem in health informatics is to read a message from another healthcare organization and...

A: In order to solve the problem we would follow these steps:Break the entire string into tokens separa...

Q: Question: Write a program that prompts the user to enter the number of students and each student's s...

A: Solution:The python program has the following algorithm:Prompt and read the total number of students...

Q: How important is wifi to expansion of computer poliferation

A: Importance of Wi-Fi expansion to computer proliferation:Increased scalability:Wi-Fi is used to avoid...

Q: how to to assign charather to perform additions (+), subtractions (-), multiplications (*), division...

A: Program plan:Include necessary header files.Declare the “namespace”.Define the “main()” function.Dec...

Q: Using adders, subtracters, comparers, copiers, or multipliers, draw block diagrams for Turing machin...

A: Solution:Turing machine:The Turing machine is theoretical computing machine that can be used to iden...