`
奎河少年
  • 浏览: 23706 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表

java反射(四)

import java.lang.reflect.Field; public class TestPrivate2 { public static void main(String[] args) throws Exception { Private2 p = new Private2(); Class classType = p.getClass(); Field field = classType.getDeclaredField("username"); field.setAccessible(true); field.set( ...

java反射(三)

import java.lang.reflect.Method; public class TestPrivate { public static void main(String[] args) throws Exception { Private p = new Private(); Class classType = p.getClass(); Object obj = classType.newInstance(); Method method = classType.getDeclaredMethod("echo", n ...

java反射(二)

import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class ReflectionTester { @SuppressWarnings("unchecked") public Object objectCopy(Object object) throws Exception { Class<?> classType = object.getClass(); C ...

java反射(一)

import java.lang.reflect.Method; public class DumpMethod { public int add(int a, int b) { return a + b; } public String echo(String message) { return "Hello" + " " + message; } public static void main(String[] args) throws Exception { Class<?> cla ...
public class Shuixianhuashu { public static void main(String[] args) { for (int i = 100; i <= 999; i++) { int baiwei = i / 100; int shiwei = (i - (baiwei * 100)) / 10; int gewei = i - baiwei * 100 - shiwei * 10; if (i == (Math.pow(gewei, 3) + Math.pow(shiwei, 3) + Math.pow( ...

10-50随机数

import java.util.Random; //求每个数字出现的次数、出现次数最多的数、出现最大次数的值的数字 public class RandomTest2 { public static void main(String[] args) { int[] count = new int[41]; Random random = new Random();//产生随机数 for(int i=0;i<50;i++){ int number = random.nextInt(41)+10;//产生随机数[10,50] System.out.p ...
import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class MapTest3 { public static void main(String[] args) { HashMap hashMap = new HashMap(); for(int i=0;i<args.length;i++){ if(hashMap.get(args[i]) == null){ hashMap.put(args[i], new Integer(1 ...
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class MapTest4 { public static void main(String[] args) { HashMap map = new HashMap(); map.put("1", "a"); map.put("2", "b"); map.pu ...

用keySet遍历Map

import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class MapTest2 { public static void main(String[] args) { HashMap hashMap = new HashMap(); hashMap.put("1", "a"); hashMap.put("2", "b"); hashMap.put(" ...
public class TestRandom { public static void main(String[] args) throws Exception { typeTextByRandom("data/data1.txt"); } public static void typeTextByRandom(String fileName) { RandomAccessFile raf = null; try { raf = new RandomAccessFile(fileName, "r"); ...
public class TestFib2 { public static void main(String[] args){ int value = f(4); System.out.println("value="+value); } public static int f(int x){ if(x==1 || x==2){ return 1; }else{ int f1 = 1; int f2 = 1; int f = 0; for(int i=0;i<x-2;i++){ ...
public class TestBinsarySearch { int leftIndex = 0; int rightIndex = 0; int findVal = 0; public static int binarySearch(int[] arr,int leftIndex,int rightIndex,int findVal){ if(leftIndex > rightIndex){ return -1; } int midIndex = (leftIndex + rightIndex)/2; int m ...
public class TestFib { public static void main(String[] args) { int n = f(5); System.out.println(n); } public static int f(int x){ if(x==1 || x==2){ return 1; }else{ return f(x-1)+f(x-2); } } }  
public class TestBubbleSort{ public static int[] bubbleSort(int[] arr){ for(int i=0;i<arr.length-1;i++){ boolean flag = false; for(int j=0;j<arr.length-i-1;j++){ if(arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; flag = tr ...
import java.sql.*; public class DBUtil { public static Connection getConnection(){ Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost/test","root","root"); } c ...
Global site tag (gtag.js) - Google Analytics