Вы находитесь на странице: 1из 2

Calculate angle between minute hand and hour hand when time is provided.

The hour hand of a normal 12-hour analogue clock turns 360° in 12 hours (720
minutes) or 0.5° per minute. The minute hand rotates through 360° in 60 minutes or
6° per minute.
--> Formula to calculate angle :
We willl calculate hour and minute hand angle seperately and then find difference
between both :

To calculate angle of hour hand :

hour_angle = Hour * (360/12) + Min * (360 / (12 * 60 ))


minute_angle = Min * (360/60)

program in java :

Class Test {
psvm (String [] args) {
int hour = 10;
int min = 30;
sysout (CalcAngle(hour,min));
}

public static int CalcAngle (int hour , int min ) {

{
// find position of hour's hand
int h = (hour * 360) / 12 + (min * 360) / (12 * 60);

// find position of minute's hand


int m = (min * 360) / (60);

// calculate the angle difference


int angle = Math.abs(h - m);

// consider shorter angle and return it


if (angle > 180) {
angle = 360 - angle;
}

return angle;
}

}
}

===================================================================================
===============================================

Write your own implementation of string class, where you can perform various
operation on it;
such as (length, index of, sub string) NOTE: Do not use in-built functions.

Class StringFuncations {
public static int getStringLength(String str)
{
int length=0;
char[] strCharArray=str.toCharArray();
for(char c:strCharArray)
{
length++;
}
return length;
}

public static boolean isSubstring(String string1, String string2) {


char c;
char d;
boolean match = true;
for (int i = 0; i < string1.length(); i++) {
c = string1.charAt(i);
for (int j = 0; i < string2.length(); i++) {
d = string2.charAt(i);
if (c == d) {
match = true;
} else {
match = false;
}
}
}
return match;
}

psvm (String [] args) {

String s1 = "Test1";
String s2 = "abcabc";
String s3 = "abc";

sysout("Lenght of s1 : " getStringLength(s1) );


sysout ("Is s3 substring of s2 : " isSubstring(s2,s3));

===================================================================================
===================================

Вам также может понравиться