} } } for (int j = 0; j < 3; j++) { } Answer[i][j] = cheng1[i][0] * cheng2[0][j] + cheng1[i][1] * cheng2[1][j] + cheng1[i][2] * cheng2[2][j]; shuChu(Answer); 运行结果贴图: (3)将用“;”和“,”分割的包含数字字符的字符串“23,21.3,33;34,2,1.9,2.1;3,3,1,3,4,4.9”中的数据解析出来放在一个double类型的二维数组中,以分号分割二维数组的每一行,以逗号分割每行中的各个元素。(利用String 的split方法) 程序代码: import javax.swing.plaf.basic.BasicBorders.SplitPaneBorder;
public class LX3_5 { } } /** * @param args */ public static void main(String[] args) { String[] a = \.split(\); String[][] b = new String[3][]; for (int i = 0; i < a.length; i++) { } double[][] c = new double[3][8];//第二个必须有范围,否则无法运行 for (int i = 0; i < 3; i++) { } // TODO Auto-generated method stub for (int j = 0; j < b[i].length; j++) { } System.out.println(); c[i][j] = Double.parseDouble(b[i][j]); System.out.printf(\,c[i][j]); b[i] = a[i].split(\); // 第i行的值,且split仅能放入Stringl类型 运行结果贴图:
(4)查看帮助、编写例子 利用System类中的arraycopy()方法复制数组。 分别用Arrays类中的sort方法和binarySearch方法实现数组的排序和折半查找。 程序代码: 1. 复制数组: public class LX3_6 { } 运行结果贴图: public static void main(String[] args) { } int[] old = { 1, 2, 3, 4, 5, 6, 7 }; int[] copy = new int[7]; System.arraycopy(old, 0, copy, 0, old.length); // TODO Auto-generated method stub for (int i = 0; i < copy.length; i++) { } System.out.println(copy[i]); 2. 数组排序: import java.util.*; public class LX3_7 { public static void main(String[] args) {
} } double[] te = { 7, 4, 3, 9, 0, 6 }; Arrays.sort(te); // 多种方法重载 for (int i = 0; i < te.length; i++) { } System.out.println(te[i]); 运行结果贴图: 3. 折半查找: import java.util.*; public class LX3_8 { } public static void main(String[] args) { } double[] te = { 1, 9, 21, 31, 44, 56, 78, 99 }; System.out.println(\请输入要查找的数\); Scanner input = new Scanner(System.in); int i = input.nextInt(); System.out.println(Arrays.binarySearch(te, i)); 运行结果贴图:
(5)随机生成100个小写字母,统计每个字母出现的次数,并显示出来。 (利用Math.random()方法随机产生) 程序代码: public class LX3_9 { public static void SystemOut(int[] syso) { for (int i = 0; i < syso.length; i++) { } System.out.println((char) (i + 'a') + \出现的次数是:\ + syso[i]);//i对应public static void CountNumber(char[] Count) { } int[] counts = new int[26]; for (int i = 0; i < Count.length; i++) { } SystemOut(counts); counts[Count[i] - 'a']++; //count字符减字符存到相应的位置 public static void main(String[] args) { } char[] number = new char[100]; for (int i = 0; i < number.length; i++) { } CountNumber(number); number[i] = (char) ('a' + Math.random() * ('z' - 'a' + 1)); a~z
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库实验3 方法和数组(2)在线全文阅读。
相关推荐: