Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть How To Format A String, integer, floating point number, character using the format() Method

  • Career & Tech HQ
  • 2020-05-27
  • 207
How To Format A String, integer, floating point number, character using the format() Method
java interview questions and answersjava tutorial on eclipsejava programming beginner to advancedjava programming using eclipsejava programming projects for students with source codetutorial java eclipsejavajava tutoriallearn javajava coursejava 8 tutorialjava programming for beginnersjava trainingjava for beginnersjava 8 tutorial with examplesjava 8 coursejava programming tutorialprogrammingtutorialbeginnerslearn to codestrings in java
  • ok logo

Скачать How To Format A String, integer, floating point number, character using the format() Method бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно How To Format A String, integer, floating point number, character using the format() Method или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку How To Format A String, integer, floating point number, character using the format() Method бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео How To Format A String, integer, floating point number, character using the format() Method

How To Format A String, integer, floating point number, character using the format() Method

In this video, we will discuss on the Java String format() method, which we can use to format a String. Actually, we can use this method to perform many operations like for example joining Strings and formatting the output of the String that has been joined.

In this video we will have a look at some examples on how to use this method.

1. In the first example, I will show you how to use the format() method to convert values of certain types into Strings and then joining them

String name = “Brandon Cole”;

Since this method returns a String, we will declare a String variable

String string_format = String.format(“My name is %s” , name);

System.out.println(string_format);

The output in the console will be: My name is Brandon Cole
As you can notice the Strings have been joined. The %s represents the argument position, that is used to pass the String variable name.

Here are the statements, if you want to pass other variable types

String str1 = String.format("%d", 15); // for Integer value
String str3 = String.format("%f", 16.10); // for float value
String str4 = String.format("%x", 189); // for Hexadecimal value
String str5 = String.format("%c", 'P'); // for char value
String str6 = String.format("%o", 189); // for octal value

System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
System.out.println(str5);
System.out.println(str6);
}
}


2. In the next example I want to show you how to play around formatting arguments

double height = 1.86;

Since this method returns a String, we will do a

String string_format = String.format(“My height is %.4f” , height);
System.out.println(string_format);

The output in the console will be: My height is 1.8600
Notice that our decimal number format has changed because of what we specified in the argument by writing %.4f which means that the decimal number needs to be formatted to have four figures at its decimal part

Second example with Integer values

int number = 28;

String formattedString = String.format("%06d", number);
System.out.println(formattedString);

The result in the console will show : 000028

The %06d formatted the integer value stored in variable number by adding zeros at the beginning of the integer value so that it will be made up of 6 figures


Another example with Strings

String str1 = "cool string";
String str2 = "28";

String formattedstring = String.format("My String is: %1$s, %1$s and %2$s", str1, str2);
System.out.println(formattedstring);


%1$ and %2$ are used for specifying argument positions.
%1$ is used for the first argument and refers to the first String str1
%2$ is used for the second argument and refers to the second String str2


#codingriver
#java
#programming

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]