c++文章用
C++ scanf的進偕用法 
以下提幾個 scanf 較少見的技巧,確實不難,下面直接舉例說明。
0. 指定長度 %5s
配對時,最多只收長度為 5 之字串

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class TriStar {

public static void main(String[] args) {
      int rows = 5;
      for(int i=1;i<=rows;i++)
     {
         for(int j=1;j<=rows-i;j++)
         {
           System.out.print(" ");
         }
        for(int j=1; j<=(2*i-1);j++)  //三角形
       {
          System.out.print("*");
        }
        System.out.println();
       }
    }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()

cmd cd.. (上一頁)
cmd cd (檔案名字)
cmd c:\ 回到c
============================================================================
java bin資料夾 (用於純文字編輯)->放入電腦內環境變數
變數名稱path

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class bytee
{
      public static void main(String[] args)
      {
         //如果你用byte 或 short 做運算會自動存成int
         byte b1=1,b2=2;
         byte b3=(byte)(b1+b2);
         System.out.println(b3);

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class CalculateDemo
{
public static void main(String[] args)
{
      int v1=10,v2=3;
     double d1 = 1.0*v1/v2; //等號右邊因乘上1.0會自動轉成double 形態
     double d2 = v1/v2; //因等號右邊為int 所以出來沒有小數

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class CharDemo2 {

public static void main(String[] args) {
   //printf print println 差別
    char c1 = '大';
    char c2 = '小';
    char c3 = '\u5927';
    char c4 = '\u5c0f';
    int v1 = c1;
    int v2 = c2;
    System.out.printf("中文字:%c 十進位:%d 十六進位%x 中文字:%c 十進位:%d 十六進位%X \n " ,c1,v1,v1,c2,v2,v2);
    System.out.println("中文字:"+c1+"十進位:"+ v1);//自動換行
    System.out.print("中文字:"+c1+"十進位:"+ v1);//不會換行
    System.out.printf("\n %s %s",c3,c4);
  }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class DubleFloatDemoRun {
public static void main(String[] args) {
     //Math is double type
      double d1;
     d1 = Math.random();
     System.out.println(d1);
     float f1 ;
     f1 = (float)Math.random();
     System.out.println(f1);
    double d2;
    d2 = (Math.random()*(90-65+1))+65; //95~65
     System.out.println(d2);
/*==============================================
X~Y的範圍 ( X 為亂數範圍的起始值,而 Y 為亂數值範圍的終止值)

vipwealthy 發表在 痞客邦 留言(0) 人氣()

package javaapp0421;
import java.lang.*;
 public class JavaApp0421 {

public static void main(String[] args) {
         char c1 = 'A';
         int v = c1;
         int x = 97;
        char c2 = (char)x;
        System.out.println(v);
         System.out.println(c2);
    }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class OPDemo3
{
public static void main(String[] args)
{
      int v1=1,v2=1,v3=1,v4=1;
      boolean t= v1++>1 && v2+1>1 ;
      System.out.printf("大於小於符號優先++ 如果v1運算是flase &&後面的運算就不做\n\n");
      System.out.printf("v1++>1 && v2++>1 v1=%d V2=%d\n\n",v1,v2);
      boolean t1= v3++>1 && v4++>1 ;
      System.out.printf("大於小於符號優先++ 現在v4運算是ture &&後面的運算就不做\n\n");
      System.out.printf("v3++>1 && v4++>1 v3=%d V4=%d",v3,v4);
   }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()

public class IFDemo5 {

public static void main(String[] args) {
     int num=10;
     String data = "";
     for(;;)
    {
      int temp = num % 2;
     data = temp + data;
     num = num/2;
        if(num == 0)
           break;
   }
     System.out.println("10="+data);
  }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()


十進制轉成十六進制: 
Integer.toHexString(int i) 
十進制轉成八進制 
Integer.toOctalString(int i) 
十進制轉成二進制 
Integer.toBinaryString(int i) 
十六進制轉成十進制 
Integer.valueOf("FFFF",16).toString() 
八進制轉成十進制 
Integer.valueOf("876",8).toString() 
二進制轉十進制 
Integer.valueOf("0101",2).toString() 

vipwealthy 發表在 痞客邦 留言(1) 人氣()

public class OPDemo4
{
     public static void main(String[] args)
     {
      int v1=0370,v2=20,v3=1,v4=1;
     System.out.println(" ~v2 = " + (~v2));
     System.out.println(" v1=0370 前面多0會自動變八進位 " + v1);
      }
}

vipwealthy 發表在 痞客邦 留言(0) 人氣()

1 2
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。