substring function in java.

 package program;

import java.util.*;
public class code {
   public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("enter srting=");
    String s = sc.nextLine();
    String t="";
    System.out.println("enter value of i=");
    int i=sc.nextInt();
    for(int j=i; j<s.length(); j++){
        t+=s.charAt(j);
    }
    System.out.println("substring is ="+t);
   }
}

// function 2 ->



package program;
import java.util.*;
public class code {
   public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("enter srting=");
    String s = sc.nextLine();
    String t="";
    System.out.println("enter value of i=");
    int i=sc.nextInt();
    System.out.println("enter value of j=");
    int j=sc.nextInt();
    for(int k=i; k<j; k++){
        t+=s.charAt(k);
    }
    System.out.println("substring is ="+t);
   }
}

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.