Java/Language Basics/Convert
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
Convert double to string
public class ConvertDoubleToString {
public static void main(String[] args) {
double aDouble = 0.11;
String aString = Double.toString(aDouble);
}
}
Convert int to string
public class ConvertIntToString {
public static void main(String[] args) {
int aInt = 1;
String aString = Integer.toString(aInt);
}
}
Convert string to double
public class ConvertStringToDouble {
public static void main(String[] args) {
String aString = "78";
double aDouble = Double.parseDouble(aString);
System.out.println(aDouble);
}
}
Convert string to int
public class ConvertStringToInt {
public static void main(String[] args) {
String aString = "78";
int aInt = Integer.parseInt(aString);
System.out.println(aInt);
}
}