Developer community
0 votes
949 views
asked by Expert (15k points) 15 23 31 | 949 views

1 Answer

0 votes
When the precision specifier is applied to strings, the precision specifier specifies the maximum field length. For example, %5.7s displays a string at least five and not exceeding seven characters long. If the string is longer than the maximum field width, the end characters will be truncated.
 
import java.util.Formatter;
public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();
    // Display at most 15 characters in a string.
    fmt = new Formatter();
    fmt.format("%.15s", "12345678901234567890");
    System.out.println(fmt);
 
  }
}
out put
123456789012345
 
answered by Advisor (8.4k points) 10 15 18

Related questions

0 votes
1 answer
asked by taye Sr Member (5k points) 7 9 12 | 1.2k views
0 votes
1 answer
asked by taye Sr Member (5k points) 7 9 12 | 16 views
0 votes
1 answer
asked by taye Sr Member (5k points) 7 9 12 | 1.3k views
0 votes
1 answer
asked by taye Sr Member (5k points) 7 9 12 | 17 views
0 votes
1 answer
asked by john Guru (27.1k points) 32 50 97 | 4 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users