-
Notifications
You must be signed in to change notification settings - Fork 0
/
happy.java
43 lines (38 loc) · 1005 Bytes
/
happy.java
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
import java.util.Scanner;
class happy{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int c1=0,c2=0,c3=0;
System.out.println("Enter the string ");
String s=sc.next();
char[] C=s.toCharArray();
for(char c:C)
{
if (c == '(') {
if(c1<0)
break;
c1++;
} else if (c == ')') {
c1--;
} else if (c == '{') {
if(c2<0)
break;
c2++;
} else if (c == '}') {
c2--;
}else if (c == '[') {
if(c3<0)
break;
c3++;
} else if (c == ']') {
c3--;
}
}
boolean res=c1==0 && c2==0 && c3==0;
if(res==true)
System.out.println("True");
else
System.out.println("False");
}
}