#In Java, how to print only the value instead of "OptionalDouble[value]"?"

6 messages · Page 1 of 1 (latest)

lost junco
#

I printing a OptionalDouble matrix, and in the print, instead of print only the variable value, print e.g. "OptionalDouble[2.0]". I only want to print the value (2.0 in this example) and not "OptionalDouble[2.0]".

The code:


import java.util.Scanner;
import java.ultil.OptionalDouble;

Scanner key=new Scanner(System.in);
OptionalDouble[][] mat;
mat=new OptionalDouble[3][3];
String YorN;

for(int f=0;f<mat.length,f++){
for(int c=0;c<mat.length;c++){
System.out.print("Do you want insert a value? (Yes:Y / No:N)");
YorN=key.next;
if(YorN.equals("Y")||YorN.equals("y"){
mat[f][c]=OptionalDouble.of(key.nextDouble());
}

}

}

for(int f=0;f<mat.length,f++){
for(int c=0;c<mat.length;c++){
System.out.print(mat[f][c].toString());
}

}
pure reefBOT
#

This post has been reserved for your question.

Hey @lost junco! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

zinc cliff
#

You're going to have to make a custom method that does this conversion

#

The API of OptionalDouble is (unfortunately) quite limited

lost junco
#

Ok, thanks