`
文章列表
字符串缓存类StringBuffer  实例106 创建字符串缓存类 package Chapter06.stringBuffer; public class StringBufferDemo_01 { public static void main(String[] args) { String str = "StringBuffer"; StringBuffer sb, sb1, sb2, sb3; sb = new StringBuffer(); // 创建 ...
字符串类String 实例79  创建字符串类 package Chapter06.string; public class StringDemo_01 { public static void main(String[] args) { String str0, str1, str2, str3, str4, str5, str6, str7; byte B_array[] = { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' }; char C_array[] ...
数组的排序 实例74 冒泡排序法 public class SortArray_01 { public static void main(String args[]) { int[] array = { 14, 5, 86, 4, 12, 3, 21, 13, 11, 2, 55 }; // 创建一个初始化的一维数组array System.out.println("未排序的数组:"); for (int i = 0; i < array.length; i++) { // 遍历array数组中的元素 System.out.p ...
  二维数组 实例67 二维数组的创建与使用 public class TwoArray_01 { public static void main(String[] args) { int array[][] = new int[5][6]; // 定义一个5行6列的二维数组array int n = 1; for (int i = 0; i < array.length; i++) { // 利用双重循环为数组元素赋值 for (int j = 0; j < array[i].length; j++) { array[i][j] ...
一维数组 实例55  一维数组的创建与使用 import java.util.Random; public class OneArray_01 { public static void main(String[] args) { Random rd = new Random(); // 创建Random对象 int array[] = new int[10]; // 创建一个长度为10的int型数组array System.out.println(" \narray数组中的每个元素值如下:\n"); for (int i ...
实例46 trycatch捕获异常的实例 public class CatchException_01 { public static void main(String[] args) { int array[] = { 0, 1, 2, 3, 4, 5, 6 }; try { for (int i = 0; i < 10; i++) { System.out.println("array[" + i + "]=" + array[i]); } } catch (A ...
实例35  除0发生的算术异常(ArithmeticException) public class Runtime_01 { public static void main(String[] args) { for (int i = 10; i > 0; i--) { System.out.print(" " + (i / (i - 1))); if (i % 5 == 0) System.out.println(); } } }   实例36  数组下标越界异常 public class Runtime_02 ...
实例25  求1到100之间的和 public class WhileCycle_01 { public static void main(String[] args) { int i = 0, sum = 0; while (i < 100) { ++i; sum = sum + i; } System.out.println("1到100的和为:" + sum); } }    实例26  存上100元需要多少天 public class WhileCycle_02 { public static v ...
实例14  判断输入的年份是否为闰年 import java.util.Scanner; public class Control_01 { public static void main(String[] args) { System.out.println("请输入需要进行判断是否为闰年的年份:"); Scanner sc = new Scanner(System.in); String str = sc.nextLine(); // 从控制台上获取录入的信息 if (str.length() != 4) { // 判 ...
实例2  自动提升 public class BasicTypeChange{ //创建一个修饰基本数据类型转换的类 public static void main(String[] args) { byte b = 12; char c = 'b'; short s = 13; int i = 567; long l = 678756; float ft = 23.67f; double db = 6.124d; //result声明为其他类型会出错,除非进行类型转换 double result = (ft * b) + +(l * ...
我们都知道在编程时,有些参数是不固定的,比如服务器地址,数据库名字等,像这种参数通常要做个配置文件,这样就可以很简单的修改设置了。配置文件可以用xml,ini,Properties等。Java中没有直接提供专门来读写INI文件的类,Java支持的是.properties文件的读写。JDK内置的 Java.util.Properties 类为我们操作 .properties文件提供了便利。 1、JDK中的Properties类 Properties 类存在于包Java.util中,该类继承自Hashtable。它提供了几个主要的方法: (1)、load (InputStream inStre ...
Global site tag (gtag.js) - Google Analytics