Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Numeric Literals and Type Suffixes | Primitive Data Types
Java Data Types

bookNumeric Literals and Type Suffixes

Java allows you to write numeric literals in several different forms to represent values directly in your code. The most common is the decimal form, which uses digits 0–9 without any prefix. For example, 123 is a decimal integer literal. Java also supports hexadecimal, octal, and binary representations for integer literals:

  • A hexadecimal literal starts with 0x or 0X (such as 0x7B for 123);
  • An octal literal starts with 0 (like 0173 for 123);
  • A binary literal starts with 0b or 0B (for example, 0b1111011 also equals 123).

When writing floating-point or long integer literals, you may need to add a suffix to indicate the type explicitly. By default, integer literals are of type int, and floating-point literals are of type double.

  • To specify a long literal, you append L or l (such as 123L);
  • For a float literal, use F or f (like 1.23F);
  • You can also use D or d for a double literal, though this is optional since floating-point numbers are double by default.
Main.java

Main.java

copy
12345678910111213141516171819202122232425
package com.example; public class Main { public static void main(String[] args) { int decimal = 123; int hex = 0x7B; int octal = 0173; int binary = 0b1111011; long longValue = 123L; float floatValue = 1.23F; double doubleValue = 1.23; double doubleWithSuffix = 1.23D; System.out.println("Decimal: " + decimal); System.out.println("Hexadecimal: " + hex); System.out.println("Octal: " + octal); System.out.println("Binary: " + binary); System.out.println("Long: " + longValue); System.out.println("Float: " + floatValue); System.out.println("Double: " + doubleValue); System.out.println("Double with suffix: " + doubleWithSuffix); } }

1. Which suffix must be used to indicate a long integer literal in Java?

2. What is the value of the Java binary literal 0b1010

question mark

Which suffix must be used to indicate a long integer literal in Java?

Select the correct answer

question mark

What is the value of the Java binary literal 0b1010

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Awesome!

Completion rate improved to 7.14

bookNumeric Literals and Type Suffixes

Свайпніть щоб показати меню

Java allows you to write numeric literals in several different forms to represent values directly in your code. The most common is the decimal form, which uses digits 0–9 without any prefix. For example, 123 is a decimal integer literal. Java also supports hexadecimal, octal, and binary representations for integer literals:

  • A hexadecimal literal starts with 0x or 0X (such as 0x7B for 123);
  • An octal literal starts with 0 (like 0173 for 123);
  • A binary literal starts with 0b or 0B (for example, 0b1111011 also equals 123).

When writing floating-point or long integer literals, you may need to add a suffix to indicate the type explicitly. By default, integer literals are of type int, and floating-point literals are of type double.

  • To specify a long literal, you append L or l (such as 123L);
  • For a float literal, use F or f (like 1.23F);
  • You can also use D or d for a double literal, though this is optional since floating-point numbers are double by default.
Main.java

Main.java

copy
12345678910111213141516171819202122232425
package com.example; public class Main { public static void main(String[] args) { int decimal = 123; int hex = 0x7B; int octal = 0173; int binary = 0b1111011; long longValue = 123L; float floatValue = 1.23F; double doubleValue = 1.23; double doubleWithSuffix = 1.23D; System.out.println("Decimal: " + decimal); System.out.println("Hexadecimal: " + hex); System.out.println("Octal: " + octal); System.out.println("Binary: " + binary); System.out.println("Long: " + longValue); System.out.println("Float: " + floatValue); System.out.println("Double: " + doubleValue); System.out.println("Double with suffix: " + doubleWithSuffix); } }

1. Which suffix must be used to indicate a long integer literal in Java?

2. What is the value of the Java binary literal 0b1010

question mark

Which suffix must be used to indicate a long integer literal in Java?

Select the correct answer

question mark

What is the value of the Java binary literal 0b1010

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2
some-alt