public class _07_TypeCasting {
public static void main(String[] args) {
//TypeCasting
//μ μνμμ μ€μνμΌλ‘
//μ€μνμμ μ μνμΌλ‘
//int to float, double
int score = 93;
System.out.println(score); //93
System.out.println((float) score); //93.0
System.out.println((double)score); //93.0
//float, double to int
float score_f = 93.3F;
double score_d = 98.8;
System.out.println((int)score_f); //93
System.out.println((int)score_d); //98
//μ μ+ μ€μ μ°μ°
score = 93 +(int)98.8; //93+98
System.out.println(score); //191
score_d=(double) 93 +98.8; //93.0+98.8
System.out.println(score_d); //191.8
//λ³μμ νλ³νλ λ°μ΄ν° μ§μ΄λ£κΈ°
double convertedScoreDouble = score; //191->191.0
//int -> long -> float -> double (μλ νλ³ν)
int convertedScoreInt = (int)score_d; //191.8 ->191
// double -> float -> long -> int (μλ νλ³ν)
//μ«μλ₯Ό λ¬Έμμ΄λ‘
String s1 = String.valueOf(93);
s1= Integer.toString(93);
System.out.println(s1); //93
String s2 = String.valueOf(98.8);
s2 = Double.toString(98.8);
System.out.println(s2);//93.8
//λ¬Έμμ΄μ μ«μλ‘
int i = Integer.parseInt("93");
System.out.println(i); //93
double d = Double.parseDouble("98.8");
System.out.println(d); //98.8
//μλ¬
//int error = Integer.parseInt("μλ°");
}
}