✏️ Explanatory Question

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.

👁 89 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

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);