Primitive Wrappers | java.lang | java.util

STRING API : STARTSWITH()

Enter the string

Technology

Enter the start string

Logic

"Technology" does not start with "Logic"

 

Sample Input and Output 2:

Enter the string

Technology

Enter the start string

Tech

"Technology" starts with "Tech"

 

CODE:


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter the string");

String str = sc.nextLine();

System.out.println("Enter the start string");

String s = sc.nextLine();

if(str.startsWith(s)) {

    System.out.println("\""+str+"\" starts with \""+s+"\"");

}else {

            System.out.println("\""+str+"\" does not start with \""+s+"\"");

}

}

}

 

Comments