DEV Community

pranavinu
pranavinu

Posted on

String-task

10.Check Two Strings are Equal - Using equals method - Task
{

public static void main(String[] args) {

    String student1="rav i";
    String student2="mohan";

    System.out.println(student1.equals(student2));
    System.out.println(student1.replace(" ",""));

}
Enter fullscreen mode Exit fullscreen mode

}

8)count the no of vowels in a String

{

public static void main(String[] args) {


    String name="ravi";
    int count=0;


    for(int i=0;i<name.length();i++)
    {
        char ch=name.charAt(i);
        switch(ch)
        {
        case'a':
        case'e':
        case'i':
        case'o':
        case'u':
             count=count+1;

            System.out.println(count);  
        }       
}

}
}
Enter fullscreen mode Exit fullscreen mode

9).Count Words in a String - Using split method
{

public static void main(String[] args) {
    String student="ravi mohan ";
int a=student.split(" ").length;
System.out.println(a);
Enter fullscreen mode Exit fullscreen mode

}
}

Top comments (0)