Write an application that prompts a user for two integers an
Solution
InBetween.java
public class InBetween {
// Declaring instance variables
private int firstnumber;
private int secondnumber;
// Parameterized constructor
public InBetween(int firstnumber, int secondnumber) {
this.firstnumber = firstnumber;
this.secondnumber = secondnumber;
}
// This Method will display the number between the two numbers entered by
// the user
public void inBetweenNums() {
// Checking whether the first number is greater than the second number
// or not
if (getFirstnumber() > getSecondnumber()) {
// If there is no numbers between the two numbers then display the message
if (getFirstnumber() == getSecondnumber() + 1) {
System.out.println(\"** There are no Numbers Between \"+ getSecondnumber() + \" and \" + getFirstnumber()+ \" **\");
}
//Display the numbers between the two numbers
else {
System.out.println(\"The Numbers Between \" + getSecondnumber()+ \" and \" + getFirstnumber() + \" are :\");
for (int i = getSecondnumber() + 1; i < getFirstnumber(); i++) {
System.out.print(i + \" \");
}
}
} else {
if (getSecondnumber() == getFirstnumber() + 1) {
System.out.println(\"** There are no Numbers Between \"+ getFirstnumber() + \" and \" + getSecondnumber()+\" **\");
}
else
{
//Display the numbers between the two numbers
System.out.println(\"The Numbers Between \" + getFirstnumber()+ \" and \" + getSecondnumber() + \" are :\");
for (int i = getFirstnumber() + 1; i < getSecondnumber(); i++) {
System.out.print(i + \" \");
}
}
}
}
//Setters and getters
public int getFirstnumber() {
return firstnumber;
}
public void setFirstnumber(int firstnumber) {
this.firstnumber = firstnumber;
}
public int getSecondnumber() {
return secondnumber;
}
public void setSecondnumber(int secondnumber) {
this.secondnumber = secondnumber;
}
}
__________________________________
InBetweenTest.java
import java.util.Scanner;
public class InBetweenTest {
public static void main(String[] args) {
//Declaring variables
int firstnum,secondnum;
//Scanner class object is used read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the first number enterd by the user
System.out.print(\"Enter the First Number :\");
firstnum=sc.nextInt();
//Getting the second number entered by the user
System.out.print(\"Enter the Second Number :\");
secondnum=sc.nextInt();
//Creating the InBetweenClass Object by passing the arguments
InBetween ib=new InBetween(firstnum, secondnum);
//calling the method inBetweenNums() on the InBetween Class Object
ib.inBetweenNums();
}
}
_______________________________________
Output1:
Enter the First Number :5
Enter the Second Number :6
** There are no Numbers Between 5 and 6 **
______________________________________
Output2:
Enter the First Number :4
Enter the Second Number :10
The Numbers Between 4 and 10 are :
5 6 7 8 9
_________________________Thank You


