Skip to content

Instantly share code, notes, and snippets.

@P0huber
Created August 17, 2017 18:06
Show Gist options
  • Save P0huber/404f6773142ac0980835519cb7f5d4d5 to your computer and use it in GitHub Desktop.
Save P0huber/404f6773142ac0980835519cb7f5d4d5 to your computer and use it in GitHub Desktop.
Conversion of Integers. Преобразование целых типов [Java]
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