在Java中使用s1.concat(s2)进行动态字符串连接

时间:2018-09-04 16:26:38

标签: java eclipse

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

在这里,我对于'concat'语句和'contains'语句的输出不正确。需要纠正什么?

0 个答案:

没有答案