Q:

Java program to get the last index of any given character in a string

belongs to collection: Java String Programs

0

Java program to get the last index of any given character in a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to find last index of any character in string in Java

import java.util.Scanner;

public class StringLastValue 
{
	public static void main(String[] arg)
	{
		// create object of string and scanner class.
		String S;
		Scanner SC=new Scanner(System.in);

		// enter the string.
		System.out.print("Enter the string : ");
		S=SC.nextLine();
		int index = 0;      

		// enter the element for last occurence.
		index = S.lastIndexOf('l');         

		System.out.println("Last index is : " +index);
	}
}

Output

Enter the string : IncludeHelp
Last index is : 9

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to make first alphabet capital of eac... >>
<< Java program to concatenate two strings...