javaの中でString formatとMath種類の実例は詳しく分かります。


javaの中でString formatとMath種類の実例は詳しく分かります。
java文字列フォーマット出力

@Test 
public void test() { 
  // TODO Auto-generated method stub 
  //  printf(); 
  System.out.println(String.format("I am %s", "jj"));     //%s    
  System.out.println(String.format("     %c", 'x'));     //%c   
  System.out.println(String.format("this is %b", true));   //%b     
  System.out.println(String.format("      %d", 34));     //%d       
  System.out.println(String.format("       %x", 34));   //%x        
  System.out.println(String.format("      %o", 34));     //%o       
  System.out.println(String.format("   %f", 34.0));      //%f    
  System.out.println(String.format("       %a", 34.0));    //%a        
  System.out.println(String.format("   %e", 34.0));      //%e      
  System.out.println(String.format("       %g", 34.0));    //%g      
  System.out.println(String.format("    %h", 34));      //%h     
  System.out.println(String.format("    %%"));        //%%     
  System.out.println(String.format("   %n"));         //%n    
  System.out.println(String.format("        %ty",Calendar.getInstance())); 
  System.out.println(String.format("        %tm",Calendar.getInstance())); 
  System.out.println(String.format("        %te",Calendar.getInstance())); 
  //%tx        ,x              %ty   %tm  %te   
  //         
  System.out.println(String.format("%+d", 10));        //           
  System.out.println(String.format("|%-5d|", 10));      //%-?     
  System.out.println(String.format("%04d", 10));       //              
  System.out.println(String.format("%,f", 999999999.0));   // “,”      
  System.out.println(String.format("%(f", -999999999.0));   //         
  System.out.println(String.format("%#x", 34));        //      0x 
  System.out.println(String.format("%#o", 34));        //     0 
  System.out.println(String.format("%#f", 34.0));       //         
  System.out.println(String.format("%f  %<3.1f", 34.0f));   //               (      ) 
  System.out.println(String.format("%3.1f", 34.0f));   // 
  System.out.println(String.format("%2$d,%1$s", "a",1));   // x$         
  //      
  System.out.println(String.format("         %tc", new Date()));   // tc             
  System.out.println(String.format(" ― ―   %tF", new Date()));      // tF  ― ―   (   ) 
  System.out.println(String.format(" / /   %tD", new Date()));      // tD  / /   (   ) 
  System.out.println(String.format("HH:MM:SS PM/AM   %tr", new Date())); // tR HH:MM:SS PM/AM   
  System.out.println(String.format("HH:MM:SS(24  )%tT", new Date())); // (  )tT HH:MM:SS 24    
  System.out.println(String.format("HH:MM(24  )%tR", new Date()));  // (  )tR HH:MM 24    
   
  System.out.println(String.format(Locale.US,"      %tb", new Date()));    // tb        
  System.out.println(String.format("      %tb", new Date()));       // tb        
  System.out.println(String.format(Locale.US,"      %tB", new Date()));    // tB        
  System.out.println(String.format("      %tB", new Date()));       // tB        
  System.out.println(String.format(Locale.US,"    %ta", new Date()));   // ta        
  System.out.println(String.format("    %tA", new Date()));        // tA        
  Date date = new Date(); 
  System.out.printf("       :%tA%n",date); 
  //C   ,     
  System.out.printf("       (       0):%tC%n",date); 
  //y   ,     
  System.out.printf("       (       0):%ty%n",date); 
  //j   ,      
  System.out.printf("      (      ):%tj%n",date); 
  //m   ,   
  System.out.printf("       (       0):%tm%n",date); 
  //d   , (  ,    ) 
  System.out.printf("      (       0):%td%n",date); 
  //e   , (     ) 
  System.out.printf("    (    0):%te",date); 
 //H    
    System.out.printf("2   24     (  2    0):%tH%n", date); 
    //I    
    System.out.printf("2   12     (  2    0):%tI%n", date); 
    //k    
    System.out.printf("2   24     (    0):%tk%n", date); 
    //l    
    System.out.printf("2   12     (    0):%tl%n", date); 
    //M    
    System.out.printf("2      (  2    0):%tM%n", date); 
    //S    
    System.out.printf("2     (  2    0):%tS%n", date); 
    //L    
    System.out.printf("3      (  3    0):%tL%n", date); 
    //N    
    System.out.printf("9       (  9    0):%tN%n", date); 
    //p    
    String str = String.format(Locale.US, "            ( ):%tp", date); 
    System.out.println(str);  
    System.out.printf("            ( ):%tp%n", date); 
    //z    
    System.out.printf("   GMT RFC822      :%tz%n", date); 
    //Z    
    System.out.printf("       :%tZ%n", date); 
    //s    
    System.out.printf("1970-1-1 00:00:00          :%ts%n", date); 
    //Q    
    System.out.printf("1970-1-1 00:00:00           :%tQ%n", date); 
} 

Math

@Test 
  public void test3(){ 
    BigDecimal d = new BigDecimal("123"); 
    BigDecimal e = new BigDecimal("14455552"); 
    System.out.println(Math.pow(123, 12)); 
    System.out.println(d.pow(12)); 
     
    System.out.println(Math.ceil(12.3));//ceil,    13.0 
    System.out.println(Math.floor(-12.3));//ceil,   -13.0 
    System.out.println(Math.round(13.3));//      13 
    System.out.println(Math.round(-13.5));//       -13 
    System.out.println(Math.round(-13.2));//       -13 
    System.out.println(Math.round(-13.7));//       -14 
  } 
乱数

//    
  @Test 
  public void test4(){ 
    System.out.println(Math.random());//       >=0,+b1 
    //0-100(   100) 
    int a =(int)(Math.random()*100); 
    //0-100(  100) 
    int b =(int)(Math.random()*101); 
    //30-100(  100) 
    int c =(int)(Math.random()*71+30); 
    //0-10 
    int d = (int)(Math.random()*10); 
    System.out.println(a); 
    System.out.println(b); 
    System.out.println(c); 
    System.out.println(d); 
  } 

@Test 
public void test5(){ 
  Random r = new Random(); 
  int a = r.nextInt(101);//0-100 
   
} 
シンプルフォーマット

@Test 
  public void testId() throws ParseException{ 
    String s = "411123199409203013"; 
    if(s.length()==18){ 
      String b = s.substring(6, 14); 
      String sex = Integer.parseInt(s.substring(14, 17))%2==0?" ":" "; 
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 
      Date birth = sdf.parse(b);//                      
      sdf = new SimpleDateFormat("yyyy MM dd "); 
      System.out.println("     "+sdf.format(birth)+",     "+sex); 
      String f = String.format("     %1$TY %1$Tm %1$Td ,     %2$s", birth,sex); 
      System.out.println(f); 
    }else if(s.length()==15){ 
      String b = s.substring(6, 14); 
      String sex = Integer.parseInt(s.substring(14, 17))%2==0?" ":" "; 
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 
      Date birth = sdf.parse(b);//                      
      sdf = new SimpleDateFormat("yyyy MM dd "); 
      System.out.println("     "+sdf.format(birth)+",     "+sex);//format                
       
       
    } 

読んでくれてありがとうございます。みなさんのご協力をお願いします。ありがとうございます。