Skip to content

Instantly share code, notes, and snippets.

@youngjinmo
Last active September 14, 2019 14:06
Show Gist options
  • Save youngjinmo/a4f8666c0c336e885c3c163d24c65e05 to your computer and use it in GitHub Desktop.
Save youngjinmo/a4f8666c0c336e885c3c163d24c65e05 to your computer and use it in GitHub Desktop.
Integer형으로 형변환하는 방법
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