In: Computer Science
In.java
In this program write a method called upDown that takes three integers as arguments and returns one of these 3 strings:
In the main method do the following:
read three integers from the user and call upDown for those integers, save the result in a variable, res1, and then print it.
---------- Sample run 1: Enter three integers separated by spaces: 2 0 9 These numbers are in order: none Enter three integers separated by spaces: 17 90 567 These numbers are in order: increasing different ---------- Sample run 2: Enter three integers separated by spaces: 90 9 1 These numbers are in order: decreasing Enter three integers separated by spaces: 7 3 1 These numbers are in order: decreasing same ---------- Sample run 3: Enter three integers separated by spaces: 3 3 4 These numbers are in order: none Enter three integers separated by spaces: 8 1 16 These numbers are in order: none same
SOURCE CODE:
import java.util.*;
public class Main
{
//method upDown to check sequence
increasing,decreasing or none
public static String upDown(int a,int b,int
c)
{
String s=" ";
if(a>b &&
b>c)
{
s="decreasing";
}
else if(a<b
&& b<c)
{
s="increasing";
}
else
{
s="none";
}
return s;
}
public static void main(String[] args) {
int a,b,c,d,e,f;
String res1,res2;
Scanner sc=new
Scanner(System.in);
System.out.print("Enter three
integers separated by spaces: ");
//reading integers from the
user
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
res1=upDown(a,b,c);
System.out.println("These numbers
are in order: "+res1);
System.out.print("Enter three
integers separated by spaces: ");
//reading integers from the
user
d=sc.nextInt();
e=sc.nextInt();
f=sc.nextInt();
res2=upDown(d,e,f);
System.out.println("These numbers
are in order: "+res2);
//compare if two results are equal
or not
if(res1.equals(res2))
{
//if two
strings are equal
System.out.println("same");
}
else
{
System.out.println("different");
}
}
}
CODE
SCREENSHOT:
OUTPUT:
RUN-1
RUN-2
RUN-3
RUN-4