0
import java.util.Scanner;

public class StringOps
{
    public static void main(String[] args) 
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the string\n");
    String s1=sc.nextLine();
    System.out.println("What operations do you want to do?\n1.Concat String\n2.Find substring\n3.UpperCase");
    int ch=sc.nextInt();
    if(ch==1)
    {   System.out.println("Enter the string to be concated\n");
        String s2=sc.nextLine();
        String s4=s1.concat(s2);
        System.out.println(s4);
    }
    else if(ch==2) 
    {
        System.out.println("Enter the string to be searched in the main string\n");
        String s3=sc.nextLine();
        if(s1.contains(s3))
            System.out.println("It is present");
        else
            System.out.println("Not present");
    }
    else if(ch==3)
    {
        System.out.println(s1.toUpperCase());
    }
}//end of main
}//end of class

Here, I am getting an incorrect output for the 'concat' statement, as well the 'contains' statement. What needs to be corrected?

  • Your second attempt was much better than the first, but you should still be more precise what "incorrect output" means exactly – Marged Sep 04 '18 at 18:19
  • Oh I am sorry. For the concat statement, It just displays the string s1. It doesn’t take any input for s2. – RajatVDeshpande Sep 05 '18 at 01:42

0 Answers0