Skip to content

Instantly share code, notes, and snippets.

@gnosis23
Created July 9, 2014 13:24
Show Gist options
  • Select an option

  • Save gnosis23/d441db7ea23d14775c81 to your computer and use it in GitHub Desktop.

Select an option

Save gnosis23/d441db7ea23d14775c81 to your computer and use it in GitHub Desktop.
padding string
package main;
/**
* @author: bohao
*/
public class Pad
{
public static String leftPad(String pass) {
return String.format("%10s",pass).replace(' ', '0');
}
public static String rightPad(String pass) {
return String.format("%-10s",pass).replace(' ', '0');
}
public static void main(String[] args) {
System.out.println(leftPad("4008123"));
System.out.println(rightPad("4008123"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment