Skip to main content

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); StringSystem.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.printf("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.printf("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); System.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.printf("%03d", a); 
deleted 1 character in body
Source Link
bvdb
  • 25.2k
  • 11
  • 123
  • 135

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.printlnprintf("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.println("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.printf("%03d", a); 
typo - thanks to David Miguel for pointing it out
Source Link
bvdb
  • 25.2k
  • 11
  • 123
  • 135

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.Formatformat("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.println("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.Format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.println("%03d", a); 

Let's say you want to print 11 as 011

You could use a formatter: "%03d".

enter image description here

You can use this formatter like this:

int a = 11; String with3digits = String.format("%03d", a); String.out.println(with3digits); 

Alternatively, some java methods directly support these formatters:

System.out.println("%03d", a); 
Source Link
bvdb
  • 25.2k
  • 11
  • 123
  • 135
Loading