Write a statement each to perform the following tasks on a string:

(i) Find and display the position of the last space in a string s.
(ii) Convert a number stored in a string variable x to double data type.

Short Answer
Views 17

Answer:

Statements for string operations:

(i) To find and display the position of the last space in a string s:


int lastSpaceIndex = s.lastIndexOf(' ');
System.out.println(lastSpaceIndex);

(ii) To convert a number stored in a string variable x to double data type:


double num = Double.parseDouble(x);

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.