0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Java printf()メソッド

Last updated at Posted at 2020-11-28

#1,printf() メソッドは、フォーマットに用いるメソッドです。
#2,ソースコード

Main.java
public class Main {

	public static void main(String[] args) {

		System.out.printf("%d This is a format String ", 123);

		boolean myBoolean = true;
		char myChar = '@';
		String myString = "hiro";
		int myInt = 50;
		double myDouble = 1000;

		System.out.printf("%b", myBoolean);
		System.out.printf("%c", myChar);
		System.out.printf("%s", myString);
		System.out.printf("%d", myInt);
		System.out.printf("%f", myDouble);

		System.out.printf("Hello %10s", myString); //
		System.out.printf("Hello %-10s", myString); //

		System.out.printf("You have this much money %.2f", myDouble);
		System.out.printf("You have this much money %.1f", myDouble);
		System.out.printf("You have this much money %f", myDouble);

		System.out.printf("You have this much money %+f", myDouble);
		System.out.printf("You have this much money %020f", myDouble);
		System.out.printf("You have this much money %,f", myDouble);

	}

}

#Java チュートリアル:clipboard:
:coffee: Java テキストファイル(.txt .csv)への出力 java.io.FileWriter : :white_check_mark:here
:coffee: Java テキストファイル(.txt .csv)からの入力 java.io.FileReader : :white_check_mark:here
:coffee: Java モニターからの入力 java.util.Scanner : :white_check_mark:here
:coffee: Java GUIからの入力 javax.swing.JOptionPane : :white_check_mark:here
:coffee: Java Mathクラス Math.sqrt : :white_check_mark:here
:coffee: Java 乱数の生成 java.util.Random : :white_check_mark:here
:coffee: Java Stringクラス : :white_check_mark:here
:coffee: Java Wrapperクラス : :white_check_mark:here
:coffee: Java ArrayListクラス java.util.ArrayList : :white_check_mark:here
:coffee: Java メソッド(method)の作り方とオーバーロード : :white_check_mark:here
:coffee: Java printf()メソッド : :white_check_mark:here
:coffee: Java オブジェクト(Object Oriented Programming)とコンストラクタ、スコープ(local,global) : :white_check_mark:here

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?