-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp5.java
30 lines (27 loc) · 885 Bytes
/
p5.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
import java.util.*;
class p5{
static void strcmp(String s1,String s2){
if(s1.compareTo(s2)==0)
System.out.println("Both strings are equal");
else
System.out.println("Both strings are not equal");
}
static void strcmp(String s1,String s2,int n){
if(s1.substring(0,n).equals(s2.substring(0,n)))
System.out.println("Equal upto length "+n);
else
System.out.println("not equal!!");
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String s1,s2;
int n;
System.out.println("Enter 2 strings");
s1=sc.next();
s2=sc.next();
System.out.println("Enter the number upto which charecters to be checked:");
n=sc.nextInt();
strcmp(s1,s2);
strcmp(s1,s2,n);
}
}