Question

Write an application that prompts a user for two integers and displays every integer between them....

Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger.

-------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class Inbetween {

    public static void main (String args[]) {

        // Write your code here

    }

}

Homework Answers

Answer #1
 
import java.util.Scanner;

public class Inbetween {

    public static void main (String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter two integers: ");
        int n1 = in.nextInt();
        int n2 = in.nextInt();
        if (n1 > n2 + 1) {
            for (int i = n1-1; i > n2; i--) {
                System.out.print(i + " ");
            }
            System.out.println();
        } else if (n1 + 1 < n2) {
            for (int i = n1+1; i < n2; i++) {
                System.out.print(i + " ");
            }
            System.out.println();
        } else {
            System.out.println("There are no integers between " + n1 + " and " + n2);
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. This is a java assignment. Pls help
Write an application that asks a user to enter an integer. Display a statement that indicates...
Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. ------------------------------------------ import java.util.Scanner; class EvenOdd {     public static void main(String[] args) {         // Write your code here     }     public static boolean isEven(int number) {     } }
Write an application that stores the following nine integers in an array: 10, 15, 19, 23,...
Write an application that stores the following nine integers in an array: 10, 15, 19, 23, 26, 29, 31, 34, 38. Display the integers from first to last, and then display the integers from last to first. ----------------------------------------------- public class NineInts {     public static void main (String args[]) {         // Write your code here     } } ------------------------ Please use JAVA
In JAVA: Write a program that reads an integer, a list of words, and a character....
In JAVA: Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle...
Write a program that reads an integer, a list of words, and a character. The integer...
Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle z then...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of...
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work for squares of all side lengths between 1 and 20. I keep getting the error: "AsteriskSquare.java:2: error: class Main is public, should be declared in a file named Main.java public class Main ^ 1 error"
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the area of a rectangle * based on the width and length entered by the user. */ public class RectangleArea2 {             public static void main(String[] args) { int length; //longer side of rectangle             int width; //shorter side of rectangle int area; //calculated area of rectangle Scanner input = new Scanner(System.in);                               System.out.print("Enter the length: ");            length = input.nextInt(); System.out.print("Enter...
Create a DigitsSum application that prompts the user for a non-negative integer and then displays the...
Create a DigitsSum application that prompts the user for a non-negative integer and then displays the sum of the digits. ( Java Programming )
[JAVA] Write a program that prompts the user for an integer and displays if the provided...
[JAVA] Write a program that prompts the user for an integer and displays if the provided integer is a prime number or not. A prime number is a number that is divisible only by 1 and itself. First few prime numbers are 2,3,5,7,11,13 and so on. [using if-statements, and if-else-statement ]
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • What is a management maintenance model? What does it accomplish? [MANAGEMENT OF INFORMATION SECURITY][Please provide a...
    asked 3 minutes ago
  • In recent years, different kinds of databases have emerged that do not adhere to the traditional...
    asked 4 minutes ago
  • List and describe the fields found in a properly and fully defined performance measure. [Please Describe...
    asked 5 minutes ago
  • A savvy group of graduate students are developing a new corporation, GraduateSchoolOrBust. Their mission is to...
    asked 10 minutes ago
  • Write a method called sumDiagonal() that takes a 2D array of int as an argument returns...
    asked 14 minutes ago
  • You roll two six-sided fair dice. a. Let A be the event that either a 3...
    asked 39 minutes ago
  • Consider the following reaction: A + 2B → E Using steady-state approximation determine which of the...
    asked 39 minutes ago
  • QUESTION: Study the following case, then prepare a context diagram and level zero diagram based on...
    asked 46 minutes ago
  • The pitch deck should be sent beforehand when pitching to competition judges early investors employees trade...
    asked 55 minutes ago
  • Understanding the Project Management Methodologies The project methodology is determined by the type of organization and...
    asked 1 hour ago
  • A yo-yo has a rotational inertia of 1000 g·cm2 and a mass of 127 g. Its...
    asked 1 hour ago
  • Compare and contrast Erikson's fifth stage of personality development and Marcia's theory on identity statuses. Which...
    asked 1 hour ago