Friday 6 February 2015

parrot is talking means true, if parrot is talking before hour 7 and after 20 then return true. hour limit is between 1 and 23.

import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enetr Boolean Value= ");
boolean talking=sc.nextBoolean();

System.out.print("Enter Hour value = ");
int hour=sc.nextInt();

if(talking && hour<7 || talking && hour>20)
{
System.out.println("true");
}
else
{
System.out.println("false");
}


}

}

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);
}
}

}

Given two int values, return their sum. Unless the two values are the same, then return double their sum. sumDouble(1, 2) → 3 sumDouble(3, 2) → 5 sumDouble(2, 2) → 8

Given two int values, return their sum. Unless the two values are the same, then return double their sum. 

sumDouble(1, 2) → 3
sumDouble(3, 2) → 5
sumDouble(2, 2) → 8

Solution:


import java.util.Scanner;
class Test
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enetr First Number= ");
int a=sc.nextInt();
System.out.print("Enetr First Number= ");
int b=sc.nextInt();
if(a==b)
{
int c=2*(a+b);
System.out.println(c);
}
else
{
int d=a+b;
System.out.println(d);
}

}
}

We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble. monkeyTrouble(true, true) → true monkeyTrouble(false, false) → true monkeyTrouble(true, false) → false

Q:1 



We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.

monkeyTrouble(true, true) → true
monkeyTrouble(false, false) → true
monkeyTrouble(true, false) → false

















 import java.util.Scanner;
class Test
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter bollean value for aSmile= ");
boolean aSmile=sc.nextBoolean();
System.out.print("Enetr only booblean value for bSmile=  ");
boolean bSmile=sc.nextBoolean();
if(aSmile && bSmile || !aSmile && !bSmile)
{
System.out.println("true");
}
else
{
System.out.println("false");
}
}
}