answersLogoWhite

0

Here is the final code for a program that RETURNS the number (from another method to the main method):

import java.util.*;

public class Example

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Please enter two numbers to generate a number between (inclusive) those two numbers");

System.out.println("Please enter the first:");

int d = in.nextInt();

System.out.println("Please enter the second:");

int e = in.nextInt();

int g = randomBetween(d, e);

}

public static int randomBetween(int d, int e)

{

Random random = new Random();

int f = random.nextInt(e-d+1)+d;

return f;

}

}

We are not allowed to put links in the answer to a question, so I have now put the link to a video explaining this code in the related links area.

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

How do you solve this program wap to print sum of a digit of an inputed number?

wap to print all the arnstrong no. between 100&1000


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


Write a program large number and small number among n numbers by using If statement?

12


How do you find out addition of all numbers between two inputed numbers in for loop?

First of all we will describe how our program should be working.After entering number 1 and 5 I want it count 2 + 3 + 4 and return 9. After entering 4 and 9 it should count 5 + 6 + 7 + 8 and return 26. After entering X and X I should get 0. If I enter X and X - 1 I should get and error.Here is the code of such application:#include int main() {int firstNum, secondNum, sum, tmp;printf("Please enter first number: ");scanf("%d", &firstNum);printf("Please enter second number: ");scanf("%d", &secondNum);if (secondNum < firstNum) {printf("Sorry, second number must be higher than first one.\n");return 1;}sum = 0;for (tmp = firstNum + 1; tmp < secondNum; tmp++) {sum += tmp;}printf("All numbers between %d and %d sum equals %d\n", firstNum, secondNum, sum);return 0;}Testing:Please enter first number: 1Please enter second number: 5All numbers between 1 and 5 sum equals 9Please enter first number: 4Please enter second number: 9All numbers between 4 and 9 sum equals 26


Write a c program to find out the prime numbers between 1 to 500?

To write a C program to find prime numbers between 1 to 500, you can use a nested loop structure. In the outer loop, iterate from 2 to 500, and in the inner loop, check if the number is divisible by any number from 2 to the square root of the number. If it is not divisible by any number other than 1 and itself, then it is a prime number. Print out all prime numbers found within the specified range. Remember to include necessary header files, such as &lt;stdio.h&gt;, and use appropriate logic to implement the program efficiently.

Related Questions

How do you solve this program wap to print sum of a digit of an inputed number?

wap to print all the arnstrong no. between 100&amp;1000


Prime numbers between 1 to 10 in microprocessor 8085?

program to find prime number in 8085 microprocessor


Program to count the number of numbers in an array using 8085 microprocessor?

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.


What number is between the fractions 10.40 and 20.50?

These are decimals and there are an infinite number of numbers between these numbers.


What number is between 3 5 and 7 10?

There are no prime numbers in between these numbers. The only whole number between them is 6


What is next decimal number of the number 65?

There is no such thing as a "next" decimal number. Numbers are infinitely dense: that is, between any two numbers there are infinitely many numbers. Therefore, given any number claiming to be next after 65, there are infinitely many numbers between 65 and that number - The smallest of these has a better claim at being next. But there are infinitely many numbers between 65 and this number.There is no such thing as a "next" decimal number. Numbers are infinitely dense: that is, between any two numbers there are infinitely many numbers. Therefore, given any number claiming to be next after 65, there are infinitely many numbers between 65 and that number - The smallest of these has a better claim at being next. But there are infinitely many numbers between 65 and this number.There is no such thing as a "next" decimal number. Numbers are infinitely dense: that is, between any two numbers there are infinitely many numbers. Therefore, given any number claiming to be next after 65, there are infinitely many numbers between 65 and that number - The smallest of these has a better claim at being next. But there are infinitely many numbers between 65 and this number.There is no such thing as a "next" decimal number. Numbers are infinitely dense: that is, between any two numbers there are infinitely many numbers. Therefore, given any number claiming to be next after 65, there are infinitely many numbers between 65 and that number - The smallest of these has a better claim at being next. But there are infinitely many numbers between 65 and this number.


find the prime number between two number?

There need not be any prime number between them.


What are two numbers that are in between the number 0.6 on the number line?

It is impossible to be in between one number.


What is the rational number between square root of 29 and 45?

There are an infinite number of rational numbers between these two numbers, but the only positive integer between these numbers is 6.


What between 4 and 5 in number lines?

There are infinitely many numbers between any two different numbers. To find a number exactly in the middle between two numbers, calculate the average. That is, add the two numbers, then divide the result by 2.


What is the median number of 11.5 and 22.5?

It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.It is the number halfway between them or half of the total of the two numbers, so 17 is the median.


What number is between 1 and 69?

There are an infinite number of numbers. 2 is an example of one of the numbers between 1 and 69.