Question: 6's Treat
We are going to play a game called 6’s treat. In this, we take 2 numbers and print the larger number. However, if the 2 values have the same remainder when divided by 6, then we print the smaller value. However, in all cases, if the two values are the same, we print 0.
Write a method Met that takes in 2 integer values and prints the result as per 6’s treat.
Only write the method - assume that the Class & main method have been defined.
Use the System.out.println() statement for printing.
Example Input: 1 7
Output: 1
Example Input: 35 28
Output: 35
Example Input: 44 44
Output: 0
Answers
METHOD:::::
public static void met(int a,int b){
int result;
if(a==b){
result=0;
System.out.println(result);
}
else if((a%6)==(b%6)){
result=Math.min(a,b);
System.out.println(result);
}
else{
result=Math.max(a,b);
System.out.println(result);
}
}
COMPLETE CODE...
import java.util.Scanner;
public class Program
{
public static void met(int a,int b){
int result;
if(a==b){
result=0;
System.out.println(result);
}
else if((a%6)==(b%6)){
result=Math.min(a,b);
System.out.println(result);
}
else{
result=Math.max(a,b);
System.out.println(result);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int first=sc.nextInt();
int second=sc.nextInt();
Program.met(first,second);
}
}