Computer Science, asked by ssanjith, 10 months ago

Write a java statement to perform the following task
(i) Find and display the position of the last space in a string str
(ii) Extract the second character of the string str.​

Answers

Answered by poojan
5

Program:

import java.util.*;

public class Main

{

public static void main(String[] args)

       {

  String str="Lead a happy life, pal";

         System.out.println("The position of the last space in the string str is: "+(str.lastIndexOf(" ")+1));

  System.out.println("Second character of the string str is: "+ str.charAt(1));

}

}

Output:

The position of the last space in the string str is: 19

Second character of the string str is: e

Learn more:

1. Write a program to check whether it is a Lead number or not in java​

https://brainly.in/question/15644815

2. Write a program in Java to generate the following pattern using nested loops.

brainly.in/question/18819254

Similar questions