Question

In: Computer Science

Write a Java program to do the following: Specifics: Write an application that prompts a user...

Write a Java program to do the following:

Specifics:

Write an application that prompts a user for two integers and displays every integer between them. Display a message if there are no integers between the entered values.

Make sure the program works regardless of which entered value is larger. Save the file as InBetween.java.

Don’t forget to create the application/project  InBetweenTest.java Class that has the main method and an object to use the InBetween class.

Solutions

Expert Solution

// CODE: Code of InBetween.java

package application.project;
import java.util.Scanner;

public class InBetween {
    
    public void integersInBetween() {
        
        Scanner sc = new Scanner(System.in);
        int a, b;
        
        // Taking 2 integers from the user
        System.out.print("Enter the first number: ");
        a = sc.nextInt();
        System.out.print("Enter the second number: ");
        b = sc.nextInt();
        
        // If a < b then swapping a and b.
        if (a > b) {
            int temp = a;
            a = b;
            b = temp;
        }

        // Handling the case when there is no element between the numbers.
        if ((a == b) || (b == a + 1)) {
            System.out.println("No integers present between the given integers.");
        }
         
        // Printing the integers in between the provided values.
        else {
            for ( int i = a + 1; i < b; i++ ) {
                System.out.println(i);
            }
        }

    }

}


// CODE: Code of InBetweenTest.java

import application.project.InBetween;

public class InBetweenTest {
    public static void main(String[] args) {
        InBetween inBetween = new InBetween();
        inBetween.integersInBetween();
    }
}

OUTPUT:


Related Solutions

[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter...
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be...
JAVA Write a Java console application that prompts the user to enter the radius of a...
JAVA Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Programmer Notes Write and document your program per class coding conventions. Add an instance variable double radius. Generate its get/set methods. Manually type the methods getDiameter(), getCircumference(), and getArea()....
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1...
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1 and 100 inclusive. The user will be repeatedly prompted until they input a valid integer.
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a java program that prompts the user to see if they wish to encode or...
Write a java program that prompts the user to see if they wish to encode or decode a message. (a) If they choose to encode a message: i. Ask them to enter the message and store it in a String variable. ii. Once the message is entered, ask them for a “shift” integer, similar to Lab 6. iii. Using that shift, move all alphabetic characters in the message (i.e. excluding spaces and punctuation) using char and int arithmetic. Be sure...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT