好文档 - 专业文书写作范文服务资料分享网站

java从入门到精通习题

天下 分享 时间: 加入收藏 我要投稿 点赞

5.3

public class Eval { // 新建类 public static void main(String[] args) { // 主方法 String regex = \ String text = \ if (text.matches(regex)) { System.out.println(text + \是合法的手机号\ } } } 5.4

public class Eval { // 新建类 public static void main(String[] args) { // 主方法 StringBuilder builder = new StringBuilder(\ for (int i = 1; i <= 10; i++) { builder.append(i); } System.out.println(builder.toString()); } } 6.1

import java.util.*;

public class Eval { // 创建类 public static void main(String [] args) {

int arr1[]=new int[]{1,2,3,4,5}; int arr2[] = Arrays.copyOf(arr1, 3);

// 复制源数组中从下标0开始的3个元素到目的数组,从下标0的位置开始存储。 for(int i=0;i

for(int j=0;j

6.2

import java.util.*;

public class Eval { // 创建类 public static void main(String[] args) { int arr[] = new int[] { 10, 2, 3, 4, 5, 6, 7, 8, 9 }; Arrays.sort(arr); System.out.println(arr[0]); } } 6.3

import java.util.*;

public class Text { // 创建类 public static void main(String[] args) { String arr[] = new String[] { \ System.out.println(\替换前:\ for (String str : arr) { System.out.print(str+\ } Arrays.fill(arr, 2, 3, \ System.out.println(\替换后:\ for (String str2 : arr) { System.out.print(str2+\ } } } 6.4

public class Eval { // 创建类 public static void main(String[] args) { int arr[][]=new int[][]{{1,2,3},{4,5,6},{7,8,9}}; System.out.println(\数组原有内容:\ for(int i = 0;i

} 7.1

package com.lzw;

public class UseCase1 { private String name; public String getName() { return name; }

public void setName(String name) { this.name = name; } }

//另一个java文件 package com.lzw;

public class UseCase2 extends UseCase1{ public static void main(String[] args) { UseCase1 u=new UseCase1(); u.setName(\ System.out.println(u.getName()); } } 7.2

package com.lzw;

public class UseCase3 { private float height; private float width; public UseCase3(float height,float width){ this.height=height; this.width=width; } public float square(){ return height*width; } public static void main(String args[]){ UseCase3 u=new UseCase3(3.5f,4.5f); System.out.println(u.square()); } }

7.3

package com.lzw;

public class UseCase4 { public static void main(String[] args) { for(int i=0;i

public class Getint{ public static void main(String args[]) { Integer inte = new Integer(452); int myint = inte.intValue(); System.out.println(myint); } } 8.2

public class CharacterCompare { public static void main(String args[]) { Character char1 = new Character('h'); Character char2 = new Character('H'); boolean b = char1.equals(char2); System.out.println(b); Character char3 = char1.toLowerCase(char1); Character char4 = char2.toLowerCase(char2); boolean bb = char3.equals(char4); System.out.println(bb); } } 8.3

public class CreateBoolean { public static void main(String args[]) { Boolean b = new Boolean(\ String str = b.toString(); System.out.println(\ b = new Boolean(\ str = b.toString(); System.out.println(\ } }

9.1

package com.lzw;

import java.util.*;

public class RandomTest { /**@param args }

* 获取2到32之间的6个偶数,并且求这6个偶数的和 */

public static double EvenNum(double num1,double num2){ double s=0; int[] j=new int[6]; Random cres = new Random(); for (int w = (int)num1,i=0; w <= (int)num2; w += 2) { j[i] = cres.nextInt((int) num2); if (j[i]!=0&&j[i] % 2 == 0) { System.out.println(j[i]); s += j[i]; i++; } if(i==6) break; } return s; }

public static double EvenNum2(double num1,double num2){ double s=0; int[] j=new int[6]; for(int i=0,w=0;i<20;i++){ j[w]=(int)num1+(int)(Math.random()*(num2-num1)); if (j[w]!=0&&j[w] % 2 == 0) { System.out.println(\打印2到32之间的偶数(不包括32)\ s += j[w]; w++; } if(w==6) break; } return s; }

public static void main(String[] args) { System.out.println(\和为:\}

java从入门到精通习题

5.3publicclassEval{//新建类publicstaticvoidmain(String[]args){//主方法Stringregex=\Stringtext=\if(text.matches(regex)){System.out.println(text+\是合法的手机号\}}}
推荐度:
点击下载文档文档为doc格式
60q1e1c8br6h1tx45d7638ccg96mxg00702
领取福利

微信扫码领取福利

微信扫码分享