0

Variables

how to get the variable that is both String and Double.

12th Feb 2017, 8:55 AM
Poramet Supakitruengroj
Poramet Supakitruengroj - avatar
4 Antworten
0
A variable cannot have two different data types. It can be a string or a double. But you can do this. String str = "12.5"; double num = Double.parseDouble(str); First you can create string with double type value but it will be string only and then you can convert it to double.
12th Feb 2017, 9:23 AM
Varun Moghe
Varun Moghe - avatar
0
and then it can calculate as double ,right?
12th Feb 2017, 9:27 AM
Poramet Supakitruengroj
Poramet Supakitruengroj - avatar
0
Yes after converting it to double you can perform any arithmetic operations on it.
12th Feb 2017, 9:37 AM
Varun Moghe
Varun Moghe - avatar
0
if I want to check a=me and run like this String a="me"; if a="me" { System.out.print("ok"); } it cant run if because a is string. so how can i do like this? thanks for helping :)
12th Feb 2017, 2:18 PM
Poramet Supakitruengroj
Poramet Supakitruengroj - avatar