
Hi I was given help with the problem with the java
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);
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 6 steps with 5 images

- I have been working on writing a java program (that goes with another I just got finished- see below CollegeCourse & Student) that prompts user to put in letter grades (A-F) for 5 different courses for a total of 10 different students. So I need to prompt user to input a student ID, then the 1st course ID, then the grade, then the 2nd course ID- then grade, the the 3rd course ID then grade, then the 4th course ID then grade, then finally the 5th course ID then grade. Then it needs to go through the same thing 10 times (for a total of 10 students). It also says the user is asked to "Enter ID for student #s" where s is an integer from 1 through 10, indicating the student (and I don't really know how to do that but I tried as I googled java); AND "Enter course ID #n, where n is an integer from 1 through 5, indicating the course number. And last it needs to verify for grade entry that only the A, B, C, D, or F are entered.I started writing notes to try to keep track of where thing are…arrow_forwardIn Java 8, I want the program to capture the current year and compare it to an input value. Specifically, the user is asked to enter the last two digits of a year that will be output. If those two digits are greater than the last two digits of the current year, the program will print to console a “19” before the two digits the user inputted. If the two digits that the use input are less than or equal to the last two digits of the current year, the program will print to the console a “20” before the two digits the user inputted. For instance, if the current year is 2023, and the user input the integer number “74”, the program would output to the console “1974”. If the current year is 2023, and the user input the integer number “19”, the program would output to the console “2019”. The user is not asked to enter the current year; the program captures that automatically. The user only enter the last two numbers of a year. Hopefully, that's enough to go by and clear enough. I need the code,…arrow_forwardIN JAVA - Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer. End with a newline. Ex: If the input is: -15 10 the output is: -15 -10 -5 0 5 10 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last. BASE CODE: import java.util.Scanner; public class LabProgram { public static void main(String[] args) { /* Type your code here. */ }}arrow_forward
- How do I develop an algorithm and program for computing the month-by-month balance in your savings account for 12 months? You can make one transaction – a deposit or a withdrawal - each month. Interest is added to the account at the beginning of each month. The monthly interest rate is the yearly percentage rate divided by 12. However, it's in Java Code with loop methods.arrow_forwardHow would I solve this in Java? it has to: return a string for the day of the week, param offset -the offset from Thursday, and return the name of day of the week.arrow_forwardDon't use Math.pow and the programming language is Java.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





