1.http://www.ithome.com
code review(程式碼審查)
Design Pattern
class MyP5_66 {
public static void main(String[] args) {
System.out.println(Float.toHexString(3.75f));
}
}
---------------------------------------------------------------------------
// 顯示關係運算子、相等運算子、邏輯否定運算子所產生的值
import java.util.Scanner;
class BooleanTester {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("整數a:"); int a = stdIn.nextInt();
System.out.print("整數b:"); int b = stdIn.nextInt();
System.out.println("a < b = " + (a < b));
System.out.println("a <= b = " + (a <= b));
System.out.println("a > b = " + (a > b));
System.out.println("a >= b = " + (a >= b));
System.out.println("a == b = " + (a == b));
System.out.println("a != b = " + (a != b));
System.out.println("!(a==0) = " + !(a == 0));
System.out.println("!(b==0) = " + !(b == 0));
}
}
------------------------------------------------------------------------------------
import java.util.Scanner;
class MyP6_5 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("元素數:");
int n = stdIn.nextInt();
int[] a = new int[n];
for (int i = 0; i < n ; i++) {
System.out.print("a[" + i + "] = ");
a[i] = stdIn.nextInt();
}
System.out.print("a = {");
for (int i = 0 ; i < n-1; i++)
System.out.print(a[i] + ",");
System.out.println(a[n-1]+"}");
}
}
---------------------------------------------------------------------------
// 求出並顯示陣列所有元素的總和(強化型for敘述)
class ArraySumForIn {
public static void main(String[] args) {
double[] a = { 1.0, 2.0, 3.0, 4.0, 5.0 };
for (int i = 0; i < a.length; i++)
System.out.println("a[" + i + "] = " + a[i]);
double sum = 0; // 總和
for (double i : a)
sum += i;
System.out.println("所有元素的總和為" + sum + "。");
}
}
---------------------------------------------------------------------------------------
// 以1、2、3、4、5初始化陣列的各個元素後顯示
class IntArrayInit {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5};
a = new int[] {10,20,30,40,50};
for (int i = 0; i < a.length; i++)
System.out.println("a[" + i + "] = " + a[i]);
}
}
--------------------------------------------------------------------------------
// 輸入陣列所有元素的值並顯示
import java.util.Scanner;
class IntArrayScan {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("元素數:");
int n = stdIn.nextInt(); // 輸入元素數
int[] a = new int[n]; // 產生陣列
for (int i = 0; i < n; i++) {
System.out.print("a[" + i + "] = ");
a[i] = stdIn.nextInt();
}
for (int i = 0; i < n; i++)
System.out.println("a[" + i + "] = " + a[i]);
}
}
-----------------------------------------------------------------------------
// 因輸出回列首而改寫顯示完成的字元
class CarriageReturn {
public static void main(String[] args) {
System.out.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
System.out.println("\r12345\\");
}
}
------------------------------------------------------------------------------------
// 從0.0開始遞增0.001至1.0為止,並且顯示其總和(以float控制迴圈)
class FloatSum1 {
public static void main(String[] args) {
float sum = 0.0F;
for (float x = 0.0F; x <= 1.0F; x += 0.1F) {
System.out.println("x = " + x);
sum += x;
}
System.out.println("sum = " + sum);
}
}
2011年6月30日 星期四
2011-06-30 JAVA
1.http://javaclubtw.blogspot.com/
2.windows 記憶體配置
4. int 4bytes * 8 = 32bits
long 8bytes * 8 = 64bits
char 2bytes * 8 = 16bits
boolean 2bytes * 8 = 16bits
float 4bytes * 8 = 32bits
double 8bytes * 8 = 64bits
--------------------------------------------------------------------------
class MyP5_60 {
class static void main(String[] args) {
long x = 10; //10為int,casting(改型)
}
}
--------------------------------------------------------------------
class MyP5_60 {
class static void main(String[] args) {
long x = 2148000000L; //預設為int,compiler錯誤;加L則OK!
System.out.println("Long整數測試: " + x);
}
}
2.windows 記憶體配置
3.Linux記憶體配置
4. int 4bytes * 8 = 32bits
long 8bytes * 8 = 64bits
char 2bytes * 8 = 16bits
boolean 2bytes * 8 = 16bits
float 4bytes * 8 = 32bits
double 8bytes * 8 = 64bits
--------------------------------------------------------------------------
class MyP5_60 {
class static void main(String[] args) {
long x = 10; //10為int,casting(改型)
}
}
--------------------------------------------------------------------
class MyP5_60 {
class static void main(String[] args) {
long x = 2148000000L; //預設為int,compiler錯誤;加L則OK!
System.out.println("Long整數測試: " + x);
}
}
訂閱:
意見 (Atom)