1 / 8

1 int [][] x={{1},{2,3},{4,5,6}; System.out.print(x[2][2]);

1 int [][] x={{1},{2,3},{4,5,6}; System.out.print(x[2][2]); System.out.print(x[1].length) 2 写出结果 String a1=new String(“abc”); String a2 = “abc”; String a3 = “abc”; System.out.println(a1==a2); System.out.println(a2==a3);

gagan
Download Presentation

1 int [][] x={{1},{2,3},{4,5,6}; System.out.print(x[2][2]);

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1 int [][] x={{1},{2,3},{4,5,6}; System.out.print(x[2][2]); System.out.print(x[1].length) 2 写出结果 String a1=new String(“abc”); String a2 = “abc”; String a3 = “abc”; System.out.println(a1==a2); System.out.println(a2==a3); System.out.println( a1.equals(a2) ); System.out.println( a1.equals(a3) ); int k = a1.compareTo(a2); System.out.println( k);

  2. 3 写出实现如下功能的代码。 String s1 = new String( “ abcd1234abab”); 1) s1中有无 “c” 字符, 位置? 2)s1 中有几个ab,位置如何? 3)取出 s1 中的 “34ab”。 4)把 s1 转换成大写存入字符串 s2 5) 把 s1 字符串中的ab 转换成 car,存入s3。 4 将 字符串 “ab12cd123ef”中的数值12,123取出并转换成整数,然后相加后输出。 5 在数组中存储 10 个学生的姓名,然后查找“李开” 是否在其中。

  3. 6 计算机随机产生一个0-100之间的数,然后你可以猜3次,计算机给出比随机数“大”、“小”、“正确”的提示。(Math.random() 返回 0-1之间的小数) 7编写程序,产生10个int随机数。从大到小排序输出。 8 输出Fibonacci 数列的前 n项 :1,1 ,2,3,5,8,13,21 ……

  4. 4 • 6 • 1 7 15 37 24 61 1 2 3 2 3 5 = • 9 完成两个矩阵相乘,结果用数组返回。

  5. 10 输出如下图型,行数 n 可变。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

  6. double []data = new double[10]; //排序 final int COUNT = 10; double nTemp; for (int i=0;i<COUNT;i++) data[i] = Math.round( Math.random()* 100 ); for (int i=0;i<COUNT;i++) for(int j=i+1;j<COUNT;j++) if (data[i]>data[j]){ nTemp=data[i];data[i]=data[j];data[j]=nTemp;} for (int i=0;i<COUNT;i++) System.out.println( data[i]);

  7. String s1 = new String( "abcd1234abab"); System.out.println( s1.indexOf("c") ); int nPos=0 ,nCnt=0; while (1>0){ nPos = s1.indexOf("ab",nPos ); if (nPos == -1) break; else { nCnt++; System.out.println(nPos ); nPos++; } } System.out.println( nCnt); System.out.println( s1.substring(6,10) ); String s2; s2=s1.toUpperCase(); System.out.println( s2); String s3; s3 = s1.replaceAll("ab","car"); System.out.println( s3);

  8. n = Integer.parseInt(s1); int d[ ][ ]; d = new int[n][ ]; //n 行 d[0] = new int[1]; d[0][0]=1; d[1] = new int[2]; d[1][0]=1; d[1][1]=1; //第2行 for (int i=2;i<n;i++ ){ d[i]= new int[i+1]; //列数 = 行数+1 d[i][0]=1;d[i][i] = 1; //第一列,最后一列=1 for (int j=1;j<i;j++) d[i][j] = d[i-1][j-1]+d[i-1][j]; } for (int i=0;i<n;i++){ for (int j=0;j<20-i;j++) System.out.print(" "); for (int j=0;j<=i;j++) System.out.print(d[i][j]+" " ) ; System.out.println(); //最后一列 }

More Related