Question

In: Computer Science

I need it in java. Write a program that will print if n numbers that the...

I need it in java.

Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times asking for an integer number and for each number that the user input it will present whether the number is or not within the Min-Max range (including their respective value). As an example, if the user inputs: "3 2 5 8 4 2" the output would be:

8 is not within the range between 2 and 5
4 is within the range between 2 and 5
2 is within the range between 2 and 5

Solutions

Expert Solution

Solution for the given question are as follows -

Code :

import java.util.*;
public class Demo
{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       // local variable declaration
       int n, min, max;
       // get inputs from user
       System.out.println("How many elements you want :");
       n = sc.nextInt();
       System.out.println("Enter min and max range :");
       min = sc.nextInt();
       max = sc.nextInt();
       int []a = new int[n];
       System.out.println("Enter "+ n + " elements : ");
       for (int i = 0; i< n ; i++ ) {
       a[i] = sc.nextInt();
       }
       // check number is between min and max
       for (int i = 0; i< n ; i++ ) {
       if (a[i] >= min && a[i] <= max) {
       System.out.println(a[i]+ " is within the range between "+ min + " and "+ max);
       } else {
       System.out.println(a[i]+ " is not within the range between "+ min + " and "+ max);
       }
       }
   }
}

Code Screen Shot :

Output :


Related Solutions

1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to...
1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to 1000 which are divisible by 3, 5 and by both numbers. (b) Differentiate between instance and local variable in Java (c) In a tabular form, differentiate between instance and class variable
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
Write a Java program to generate random numbers in the following range a. 1 <=n <=...
Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 JAVA PROGRAMMING
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1....
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1. It is compiled and runs natively 2. It is interpreted but not compiled 3. It is compiled into byte code and executed by the Java Virtual Machine 4. It is magic Please enter your answer 1 Sorry that answer is not correct. The correct answer is 3 Correct output: How is a Java source file executed? 1. It is compiled and runs natively 2....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT