User:Binari: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 135: | Line 135: | ||
} |
} |
||
in.close(); |
in.close(); |
||
} |
|||
} |
|||
</lang> |
|||
==String matching== |
|||
<lang java> |
|||
import java.util.*; |
|||
import java.lang.*; |
|||
class matching { |
|||
public static void main(String[] args) { |
|||
String s1,s2; |
|||
String t1="no",t2="no",t3="no"; |
|||
Scanner iste=new Scanner(System.in); |
|||
System.out.print("First string: "); |
|||
s1=iste.next(); |
|||
System.out.print("Second string: "); |
|||
s2=iste.next(); |
|||
if (s1.startsWith(s2)) { t1="yes"; t3="yes"; } |
|||
if (s1.endsWith(s2)) { t2="yes"; t3="yes"; } |
|||
if (s1.indexOf(s2)!=-1) t3="yes"; |
|||
System.out.println("First string:"); |
|||
System.out.println("starts with second string? "+t1); |
|||
System.out.println("contains the second string at any location? "+t3); |
|||
System.out.println("ends with second string? "+t2); |
|||
} |
} |
||
} |
} |