I am supposed to extract the double values from the following string:
r ( 4.5, 1.0 ) 10.5 7 ;
However my code deletes everything but the digits and that's not what I want. My code:
import java.io.File;
import java.util.Scanner;
public class mine {
public static void main(String[] args) throws Exception
{
String str;
String numbers;
Scanner SC=new Scanner(System.in);
System.out.print("Enter string that contains numbers: ");
str=SC.nextLine();
//extracting string
numbers=str.replaceAll("[^0-9]", "");
System.out.println("Numbers are: " + numbers);
}
}
Output of my code:
Enter string that contains numbers: r ( 4.5, 1.0 ) 10.5 7
Numbers are: 45101057
I want to find a way to assign the numbers to variable. So for example using the following string: r ( 4.5, 1.0 ) 10.5 7
(Assuming a,b,c,d are already declared)
I want this:
a = 4.5
b = 1.0
c = 10.5
d = 7