List of usage examples for java.lang String format
public static String format(String format, Object... args)
From source file:Main.java
public static void main(String[] args) { for (char ch = Character.MIN_VALUE; ch < Character.MAX_VALUE; ch++) { if (Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR == Character.getDirectionality(ch)) { String s = String.format("\\u%04x", (int) ch); System.out.println(s); }/*from ww w . j av a 2 s .c o m*/ } }
From source file:Main.java
public static void main(String[] args) { double numberToRound = 12345.6789; DecimalFormat df = new DecimalFormat("0.000"); System.out.println("Rounded number = " + df.format(numberToRound)); System.out.println(String.format("Rounded number = %.3f", numberToRound)); }
From source file:Main.java
public static void main(String[] args) { double operation = 890.0 / 1440.0; BigDecimal big = new BigDecimal(operation); big = big.setScale(4, RoundingMode.HALF_UP); double d2 = big.doubleValue(); System.out.println(String.format("operation : %s", operation)); System.out.println(String.format("scaled : %s", d2)); }
From source file:Main.java
public static void main(String args[]) { String format = "|%1$-10s|%2$-10s|%3$-20s|\n"; System.out.format(format, "A", "AA", "AAA"); System.out.format(format, "B", "", "BBBBB"); System.out.format(format, "C", "CCCCC", "CCCCCCCC"); String ex[] = { "E", "EEEEEEEEEE", "E" }; System.out.format(String.format(format, (Object[]) ex)); }
From source file:Main.java
public static void main(String[] args) { LocalDate startEmployment = LocalDate.of(2011, Month.FEBRUARY, 1); LocalDate today = LocalDate.now(); long numberOfDays = startEmployment.until(today, ChronoUnit.DAYS); System.out.println(String.format("%d", numberOfDays)); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy"); String trouble = "18?11?2003"; String goodOne = "18-11-2003"; Date date = simpleDateFormat.parse(goodOne); System.out.println(date);//w w w . j av a 2 s . c o m date = simpleDateFormat.parse(trouble); System.out.println(date); System.out.println(String.format("\\u%04x", (int) trouble.charAt(2))); System.out.println(String.format("\\u%04x", (int) goodOne.charAt(2))); }
From source file:cl.sebastian.random.run.App.java
/** * @param args the command line arguments *///from w ww .j a v a2 s. co m public static void main(String[] args) { // TODO code application logic here long numero = RandomUtils.nextLong(1000000000000000000L, Long.MAX_VALUE); String aleatoreo = String.format("private static final long serialVersionUID = %dL;", numero); System.out.println(aleatoreo); }
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); long second = 1000l; long minute = 60l * second; long hour = 60l * minute; // parsing input Date date1 = dateFormat.parse("02/26/2015 09:00:00"); Date date2 = dateFormat.parse("02/26/2015 19:30:00"); // calculation long diff = date2.getTime() - date1.getTime(); // printing output System.out.print(String.format("%02d", diff / hour)); System.out.print(":"); System.out.print(String.format("%02d", (diff % hour) / minute)); System.out.print(":"); System.out.print(String.format("%02d", (diff % minute) / second)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection dbConnection = null; String myConnectionString = ""; myConnectionString = "jdbc:mysql://192.168.1.3:3306/mytestdb"; dbConnection = DriverManager.getConnection(myConnectionString, "root", "whatever"); PreparedStatement stmt = dbConnection.prepareStatement("SELECT * FROM jdbctest"); ResultSet rs = stmt.executeQuery(); int i = 0;//from ww w. j ava2s .c om int j = 0; String s = ""; while (rs.next()) { i++; j = rs.getInt("id"); s = rs.getString("textcol"); } System.out.println(String.format("Finished reading %d rows.", i)); rs.close(); stmt.close(); dbConnection.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Connection conn = null;//from ww w . j a v a 2 s . c om Statement s = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};" + "Server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "Database=myDb"); s = conn.createStatement(); s.executeQuery("SELECT * FROM dbo.SalesSummary WHERE 0 = 1"); ResultSet rs = s.getResultSet(); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { System.out.println(String.format("-- Column %d --", i)); System.out.println(String.format("Column name: %s", rsmd.getColumnName(i))); System.out.println(String.format("Database-specific type name: %s", rsmd.getColumnTypeName(i))); System.out.println(String.format("Column size (DisplaySize): %d", rsmd.getColumnDisplaySize(i))); System.out.println(String.format("java.sql.Type of column: %d", rsmd.getColumnType(i))); System.out.println(); } s.close(); conn.close(); }