Please Debug this program so that it will run properly in eclipse. Write an appl
ID: 3770414 • Letter: P
Question
Please Debug this program so that it will run properly in eclipse.
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
import java.util.Scanner;
public class Inbetween
{
public static void main(String[] args)
{
int x,y,min, max;
System.out.println(" Enter first number");
Scanner in = new Scanner(System.in);
x = in.nextInt();
System.out.println(" Enter second number");
y = in.nextInt();
if(x>y) {min=y; max=x;}
else {min=x; max=y; }
if((x==y)||(max=min+1))
{
System.out.println("There are no integers between "+x+ and +y); }
else{
for(int i=min+1;i<max;i++)
{ System.out.println(i);
System.out.println(" ");
}
}
}}
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class InBetween
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int a,b;
Scanner input = new Scanner(System.in);
a = input.nextInt();
b = input.nextInt();
if(a>b)
{
int temp = a;
a = b;
b = temp;
}
if(a==b || b==(a+1))
System.out.println("There are no integers inbetween two inputed numbers.");
else
{
for(int i=a+1;i<b;i++)
System.out.print(i+" ");
}
}
}