-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(loop + conditional ) problems
91 lines (69 loc) · 2.63 KB
/
(loop + conditional ) problems
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* BigLight
Gian and Suneo want their heights to be equal so they asked Doraemons help. Doraemon gave a big light to both of them but both big lights have different speeds of magnifying. Let us assume the big light given to Gian can increase the height of a person by v1 m/s and that of Suneos big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not.
Given the initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.
Input
The only line of the input contains 4 spaced integers, h1(height of gian), h2(height of suneo), v1(speed of Gians big light), and v2(speed of Suneos big light).
Constraints
1 <= h2 < h1<=10000 1 <= v1 <= 10000 1 <= v2 <=10000
Output
Print true if their height will become equal at some point (as seen by Doraemon) else print false.
Example
Sample input
4 2 2 4
Sample output
true
Explanation
Height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal.
Sample Input
5 4 1 6
Sample Output
false
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc =new Scanner(System.in);
int h1 =sc.nextInt();
int h2 =sc.nextInt();
int v1 =sc.nextInt();
int v2 =sc.nextInt();
while(h1!=h2){
h1 =h1+v1;
h2 =h2+v2;
if(h2>h1){
break;
}
}
if(h1==h2){
System.out.println(true);
}
else{
System.out.println(false);
}
}
}
/*
Which angled triangle
Given the 3 sides of a triangle, find out whether it is acute-angled, right-angled, or obtuse-angled.
You need to output 1 for acute, 2 for right-angled, and 3 for an obtuse-angled triangle. You can assume that the input values always form a triangle and are valid integers.
Note:
A triangle is acute-angled, if twice the square of the largest side is less than the sum of squares of all the sides.
A triangle is obtuse-angled, if twice the square of its largest side is greater than the sum of squares of all the sides.
A triangle is right-angled, if twice the square of its largest side is exactly equal to the sum of squares of all the sides.
Input:
3 4 5
Output:
2
Explanation:
Since 2x5x5 is equal to 5x5 + 3x3 + 4x4, So this is a right-angled triangle and hence, the answer is 2.
Input:
3 3 3
Output:
1
Explanation:
Since 2x3x3 is less than 3x3 + 3x3 + 3x3, So this is an acute-angled triangle and hence, the answer is 1
*/