-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFind Character Case
126 lines (81 loc) · 2.22 KB
/
Find Character Case
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Write a program that takes a character as input and prints either 1, 0 or -1 according to the following rules.
1, if the character is an uppercase alphabet (A - Z)
0, if the character is a lowercase alphabet (a - z)
-1, if the character is not an alphabet
Sample Input 1 :
v
Sample Output 1 :
0
**********************************************************
JAVA CODE WITH ALL TEST CASES PASSING:-
import java.lang.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
// Write your code here
Scanner sc=new Scanner(System.in);
char n = sc.next().charAt(0);
int a=n;
if(a>=65 && a<=90)
{
System.out.print("1");
}
else if(a>=97 && a<=122)
{
System.out.print("0");
}
else
{
System.out.print("-1");
}
}
}
******************************************************************
ANOTHER EASY LOGIC:-
import java.lang.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
// Write your code here
Scanner sc=new Scanner(System.in);
char c = sc.next().charAt(0);
if(c >= 'a' && c <= 'z')
{
System.out.print("0");
}
else if(c >= 'A' && c <= 'Z')
{
System.out.print("1");
}
else
{
System.out.print("-1");
}
}
}
************************************************************************
HALF TESTCASES PASSED WITH DIFFERENT LOGIC:-
import java.lang.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
// Write your code here
Scanner sc=new Scanner(System.in);
char n = sc.next().charAt(0);
boolean b1, b2;
b1=Character.isUpperCase(n);
if(b1==true)
{
System.out.print("1");
}
else if(b1==false)
{
System.out.print("0");
}
else
{
System.out.print("-1");
}
}
}
*********************************************************