You are on page 1of 4

output

Program:

Program to demonstrate String handling Functions

import java.io.*;

import java.util.Scanner;

class Stringop

public static void main(String args[])

int ch,n;

String na1=new String("");

String na2=new String("");

Scanner sc=new Scanner(System.in);

System.out.println("First name:");

na1=sc.nextLine();

System.out.println("\n second name:"+na2);

na2=sc.nextLine();

do

System.out.println("\n 1.length of strings");

System.out.println("\n 2.concatenate strings");

System.out.println("\n 3.substring of strings");

System.out.println("\n 4.exit");

System.out.println("\n enter your choice");

ch=sc.nextInt();

switch(ch)
{

case 1:System.out.println("\n length of first name:"+na1.length());

System.out.println("\n length of second name:"+na2.length());

break;

case 2:String c=na1.concat(na2);

System.out.println("\n concatenated name:"+c);

break;

case 3:String s1=na1.substring(2);

String s2=na2.substring(2);

System.out.println("\n substring of firstname:"+s1);

System.out.println("\n substring of secondname:"+s2);

break;

case 4: break;

default: System.out.println("\n invalid choice");

while(ch!=4);

You might also like