Last active
September 14, 2019 14:06
-
-
Save youngjinmo/a4f8666c0c336e885c3c163d24c65e05 to your computer and use it in GitHub Desktop.
Integer형으로 형변환하는 방법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class castingToInteger { | |
public static void main(String[] args){ | |
int a = 66; | |
double b = 3.456; | |
String c = "90"; | |
char d = 'd'; | |
System.out.println("Double to Integer : " + (int)b); | |
// Double to Integer : 3 | |
System.out.println("Double to Integer : " + (int)Math.ceil(b)); // Math 클래스로 반올림(ceil) | |
// Double to Integer : 4 | |
int temp1 = Integer.parseInt(c)+10; | |
int temp2 = Integer.valueOf(c).intValue()+10; | |
System.out.println("String to Integer : " + temp1+", "+temp2); | |
// String to Integer : 100, 100 | |
System.out.println("String to Integer : "+(Integer.parseInt(c)+10)); | |
// String to Integer : 100 | |
System.out.println("Char to Integer : " + (int)d); | |
// Char to Integer : 100 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment