Friday 6 February 2015

Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21. diff21(19) → 2 diff21(10) → 11 diff21(21) → 0

import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter any Number= ");
int n = sc.nextInt();
if(n<=21)
{
int c=21-n;
System.out.print(c);
}
else
{ int d=n-21;
System.out.print(2*d);
}
}

}

No comments:

Post a Comment