Created
August 17, 2017 18:06
-
-
Save P0huber/404f6773142ac0980835519cb7f5d4d5 to your computer and use it in GitHub Desktop.
Conversion of Integers. Преобразование целых типов [Java]
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
package com.javarush.task.task10.task1004; | |
/* | |
Задача №4 на преобразование целых типов | |
*/ | |
public class ConversionOfIntegers { | |
public static void main(String[] args) { | |
short number = 9; | |
char zero = '0'; | |
int nine = (zero + number);// 48 (0 в Unicode) + 9 = 57 | |
System.out.println((char) nine);// символ нуль '0' типа char в Java кодируется в специальной кодировке Unicode и соответствует числу 48, отсюда компиляция по умолчанию показывает нам 48+9=57. Десятичное число 57 в Unicode соответствует символу 9 (тип char). | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment