标签:sed 例子 随机数 rand 指定 排列 速度 log private
1 class Test{ 2 float i; 3 } 4 5 public class MainTest { 6 public static void main(String[] args){ 7 Test t1 = new Test(); 8 Test t2 = new Test(); 9 10 t1.i = 111; 11 t2.i = 222; 12 13 System.out.println("ti.i = " + t1.i); 14 System.out.println("t2.i = " + t2.i); 15 16 t1 = t2; 17 18 System.out.println("ti.i = " + t1.i); 19 System.out.println("t2.i = " + t2.i); 20 21 t1.i = 233; 22 System.out.println("ti.i = " + t1.i); 23 System.out.println("t2.i = " + t2.i); 24 } 25 }
1 class Test{ 2 float i; 3 } 4 5 class FuncTest{ 6 static void func(Test t){ 7 t.i = 2.17F; 8 } 9 } 10 11 public class MainTest { 12 public static void main(String[] args){ 13 Test t = new Test(); 14 System.out.println("t.i = " + t.i); 15 FuncTest.func(t); 16 System.out.println("t.i = " + t.i); 17 } 18 }
1 class Func{ 2 static double speedNeeded(double length,double time){ 3 return length/time; 4 } 5 } 6 7 public class MainTest { 8 public static void main(String[] args){ 9 Func.speedNeeded(23.8,14.5); 10 } 11 }
1 class Dog{ 2 String name; 3 String says; 4 5 void shows(){ 6 System.out.println("name: "+name+" Says: "+says); 7 } 8 } 9 10 public class MainTest { 11 public static void main(String[] args){ 12 Dog spot = new Dog(); 13 spot.name = "spot"; 14 spot.says = "Ruff!"; 15 16 Dog scruffy = new Dog(); 17 scruffy.name = "scruffy"; 18 scruffy.says = "Wurf!"; 19 20 spot.shows(); 21 scruffy.shows(); 22 23 Dog newDog = spot; 24 System.out.println(newDog==spot); 25 System.out.println(newDog.equals(spot)); 26 } 27 }
1 import java.util.*; 2 3 class Coin{ 4 static void test(){ 5 Random r = new Random(); 6 System.out.println(r.nextInt(2)==1?"正面":"反面"); 7 } 8 } 9 10 public class MainTest { 11 public static void main(String[] args){ 12 Coin.test(); 13 } 14 }
1 public class MainTest { 2 public static void main(String[] args){ 3 long l1 = 0777; 4 long l2 = 0xC2B; 5 6 System.out.println(Long.toBinaryString(l1)); 7 System.out.println(Long.toBinaryString(l2)); 8 } 9 }
1 public class MainTest { 2 public static void main(String[] args){ 3 int number = 0; 4 for(int i =0 ;i<32;i+=2){ 5 number|=1; 6 number<<=2; 7 } 8 number|=1; 9 10 int number2 = 0; 11 number2=~number; 12 13 int r1 = number^number2; 14 int r2 = number|number2; 15 int r3 = number&number2; 16 17 System.out.println(Integer.toBinaryString(number)); 18 System.out.println(Integer.toBinaryString(number2)); 19 } 20 }
1 public class MainTest { 2 public static void main(String[] args){ 3 int number = 0b1111111111111111111111111111111; 4 5 while(number!=0) 6 { 7 number>>=1; 8 System.out.println(Integer.toBinaryString(number)); 9 } 10 11 System.out.println(number); 12 } 13 }
1 public class MainTest { 2 public static void main(String[] args){ 3 int number = 0b1111111111111111111111111111111; 4 5 number<<=1; 6 System.out.println(Integer.toBinaryString(number)); 7 8 while(number!=0) 9 { 10 number>>>=1; 11 System.out.println(Integer.toBinaryString(number)); 12 } 13 14 System.out.println(number); 15 } 16 }
1 class CharShows{ 2 static void show(char c){ 3 int number = c; 4 System.out.println(Integer.toBinaryString(number)); 5 } 6 } 7 8 public class MainTest { 9 public static void main(String[] args){ 10 CharShows.show(‘a‘); 11 CharShows.show(‘z‘); 12 CharShows.show(‘0‘); 13 CharShows.show(‘9‘); 14 } 15 }
1 class Test{ 2 static void comp(String s1, String s2){ 3 System.out.println( "s1 == s2 : " + (s1==s2?"true":"false")); 4 System.out.println("s1 != s2 : " + (s1!=s2?"true":"false")); 5 System.out.println("s1.equals(s2) : " + (s1.equals(s2)?"true":"false")); 6 } 7 } 8 9 public class MainTest { 10 public static void main(String[] args){ 11 String s1 = new String("1234"); 12 String s2 = new String("12345"); 13 14 Test.comp(s1,s2); 15 } 16 }
1 public class MainTest { 2 public static void main(String[] args){ 3 for(int i = 1;i<=100;++i){ 4 System.out.println(i); 5 } 6 } 7 }
1 import java.util.*; 2 3 public class MainTest { 4 public static void main(String[] args){ 5 int beforeNum = 0; 6 Random r = new Random(); 7 for(int i = 0;i<25;++i){ 8 int thisNum = r.nextInt(100); 9 System.out.println("new Number is : " + thisNum); 10 if(i!=0){ 11 if(beforeNum>thisNum){ 12 System.out.println("Before Number : "+beforeNum+" > thisNum : "+thisNum); 13 } 14 else if(beforeNum<thisNum){ 15 System.out.println("Before Number : "+beforeNum+" < thisNum : "+thisNum); 16 } 17 else{ 18 System.out.println("Before Number : "+beforeNum+" == thisNum : "+thisNum); 19 } 20 } 21 beforeNum = thisNum; 22 } 23 } 24 }
1 class PrimeNumber{ 2 static boolean isPrimeNumber(int number){ 3 boolean flag = true; 4 if(number==2||number==3)return true; 5 else{ 6 for(int i = 2;i<=Math.sqrt(number)+1;++i){ 7 if(number%i==0) 8 { 9 flag = false; 10 break; 11 } 12 } 13 } 14 15 return flag; 16 } 17 } 18 19 public class MainTest { 20 public static void main(String[] args){ 21 System.out.println("2 "+(PrimeNumber.isPrimeNumber(2)?"is a PN":"is Not a PN")); 22 System.out.println("3 "+(PrimeNumber.isPrimeNumber(3)?"is a PN":"is Not a PN")); 23 System.out.println("4 "+(PrimeNumber.isPrimeNumber(4)?"is a PN":"is Not a PN")); 24 System.out.println("8 "+(PrimeNumber.isPrimeNumber(8)?"is a PN":"is Not a PN")); 25 System.out.println("17 "+(PrimeNumber.isPrimeNumber(17)?"is a PN":"is Not a PN")); 26 System.out.println("24 "+(PrimeNumber.isPrimeNumber(24)?"is a PN":"is Not a PN")); 27 } 28 }
1 class IfElse1{ 2 static int result = 0; 3 static void test(int testval,int target,int begin,int end){ 4 if(testval>=begin&&testval<=end){ 5 if(testval>target){ 6 result = 1; 7 } 8 else if(testval<target){ 9 result = -1; 10 } 11 else result = 0; 12 } 13 } 14 } 15 16 class IfElse2{ 17 static int test(int testval,int target,int begin,int end){ 18 if(testval>=begin&&testval<=end){ 19 if(testval>target){ 20 return 1; 21 } 22 else if(testval<target){ 23 return -1; 24 } 25 else return 0; 26 } 27 return -1; 28 } 29 }
1 public class MainTest { 2 public static void main(String[] args){ 3 for(int i = 1;i<=100;++i){ 4 System.out.println(i); 5 if(i==99){ 6 break; //return 7 } 8 } 9 } 10 }
1 public class MainTest { 2 public static void main(String[] args){ 3 for(int i = 0;i<3;++i){ 4 switch (i){ 5 case 0: 6 System.out.println("0"); 7 //break; 8 9 case 1: 10 System.out.println("1"); 11 //break; 12 13 case 2: 14 System.out.println("2"); 15 //break; 16 } 17 } 18 } 19 }
1 class Feb{ 2 static void feb(int max){ 3 int num1 = 1; 4 int num2 = 1; 5 int newNum = 0; 6 7 System.out.println(1); 8 System.out.println(1); 9 10 while(max>=num1+num2){ 11 newNum = num1+num2; 12 num1 = num2; 13 num2 = newNum; 14 System.out.println(num2); 15 } 16 } 17 } 18 19 public class MainTest { 20 public static void main(String[] args){ 21 Feb.feb(5); 22 } 23 }
1 import java.util.*; 2 3 public class MainTest { 4 public static void main(String[] args) { 5 method(); 6 } 7 8 private static void method() { 9 int[] startDigit = new int[4]; 10 int[] productDigit = new int[4]; 11 for (int num1 = 10; num1 <= 99; num1++) 12 for (int num2 = num1; num2 <= 99; num2++) { 13 if ((num1 * num2) % 9 != (num1 + num2) % 9) 14 continue; 15 int product = num1 * num2; 16 startDigit[0] = num1 / 10; 17 startDigit[1] = num1 % 10; 18 startDigit[2] = num2 / 10; 19 startDigit[3] = num2 % 10; 20 productDigit[0] = product / 1000; 21 productDigit[1] = (product % 1000) / 100; 22 productDigit[2] = product % 1000 % 100 / 10; 23 productDigit[3] = product % 1000 % 100 % 10; 24 int count = 0; 25 for (int x = 0; x < 4; x++) 26 for (int y = 0; y < 4; y++) { 27 if (productDigit[x] == startDigit[y]) { 28 count++; 29 productDigit[x] = -1; 30 startDigit[y] = -2; 31 if (count == 4) 32 System.out.println(num1 + " * " + num2 + " : "+ product); 33 } 34 } 35 } 36 } 37 }
标签:sed 例子 随机数 rand 指定 排列 速度 log private
原文地址:http://www.cnblogs.com/tutut/p/7210684.html