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

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.
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 a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT