




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
5.3public class Eval / 新建类public static void main(String args) / 主方法String regex = 135d9;String text =if (text.matches(regex) System.out.println(text + 是合法的手机号);5.4public class Eval / 新建类public static void main(String args) / 主方法StringBuilder builder = new StringBuilder(a);for (int i = 1; i = 10; i+) builder.append(i);System.out.println(builder.toString();6.1import java.util.*;public class Eval / 创建类public static void main(String args) int arr1=new int1,2,3,4,5; int arr2 = Arrays.copyOf(arr1, 3); / 复制源数组中从下标0开始的3个元素到目的数组,从下标0的位置开始存储。 for(int i=0;iarr1.length;i+) System.out.print(arr1i); System.out.println(); for(int j=0;jarr2.length;j+) System.out.print(arr2j);System.out.println();6.2import 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(arr0);6.3import java.util.*;public class Text / 创建类public static void main(String args) String arr = new String ac, bc, dc, yc ;System.out.println(替换前:);for (String str : arr) System.out.print(str+t);Arrays.fill(arr, 2, 3, bb);System.out.println(n替换后:);for (String str2 : arr) System.out.print(str2+t);6.4public class Eval / 创建类public static void main(String args) int arr=new int1,2,3,4,5,6,7,8,9;System.out.println(数组原有内容:);for(int i = 0;iarr.length;i+)for(int j=0;jarr.length;j+)System.out.print(arrij);System.out.println();System.out.println(行列互换后数组内容:);for(int i = 0;iarr.length;i+)for(int j=0;jarr.length;j+)System.out.print(arrji);System.out.println();7.1package com.lzw;public class UseCase1 private String name;public String getName() return name;public void setName(String name) = name;/另一个java文件package com.lzw;public class UseCase2 extends UseCase1public static void main(String args) UseCase1 u=new UseCase1();u.setName(123);System.out.println(u.getName();7.2package 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.3package com.lzw;public class UseCase4 public static void main(String args) for(int i=0;iargs.length;i+)System.out.println(i);8.1public class Getintpublic static void main(String args) Integer inte = new Integer(452);int myint = Value();System.out.println(myint);8.2public 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.3public class CreateBoolean public static void main(String args) Boolean b = new Boolean(ok);String str = b.toString();System.out.println(ok: + str);b = new Boolean(true);str = b.toString();System.out.println(true: + str);9.1package 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 int6;Random cres = new Random();for (int w = (int)num1,i=0; w = (int)num2; w += 2) ji = cres.nextInt(int) num2);if (ji!=0&ji % 2 = 0) System.out.println(ji);s += ji;i+;if(i=6) break;return s;public static double EvenNum2(double num1,double num2)double s=0;int j=new int6;for(int i=0,w=0;i20;i+)jw=(int)num1+(int)(Math.random()*(num2-num1);if (jw!=0&jw % 2 = 0) System.out.println(打印2到32之间的偶数(不包括32)+jw);s += jw;w+;if(w=6) break;return s;public static void main(String args) System.out.println(和为:+EvenNum2(2,32);9.2package com.lzw;import java.text.*;public class RoundArea static public void SimpleFormat(String pattern, double value) /使用实例化对象时设置格式化模式DecimalFormat myFormat = new DecimalFormat(pattern);/实例化DecimalFormat对象String output = myFormat.format(value);/将数字进行格式化System.out.println(value + + pattern + + output); public static double GetRoundArea(double r)return Math.PI*Math.pow(r, 2);public static void main(String args) System.out.print(圆的面积为:);SimpleFormat(#.#,GetRoundArea(2);9.3package com.lzw;import java.math.*;public class UseCase /* * param args */public static BigDecimal div(double value1,double value2,int b,int r)if(b 1000) throw new MyException(参数太大了); 12.2public class Brunt public static int count(int m,int n) return m * n; public static void main(String args) throws Exception try int result = count(12315,57876876); System.out.println(result); catch (Exception e) e.printStackTrace(); 12.3public class Computer public static int getMaxComm(int m , int n) throws MyException if( m = 0 |n=0) throw new MyException(传递的参数不是正整数); if(m n) int temp = 0; temp = m; m = n; n = temp; int r = m % n; while(r!=0) m = n; n = r; r = m % n; return n; public static void main(String args) try int m = 122 , n= 0;int reslut = getMaxComm(m,n);System.out.println(m+ 和 +n+的最大共约数是:+reslut); catch (MyException e) e.printStackTrace();/另一个类public class MyException extends Exception String message;public MyException(String ErrorMessagr) message = ErrorMessagr;public String getMessage()return message;13.1package com.lzw;import java.awt.*;import javax.swing.*;public class UseCase1 extends JFrame/* * */private static final long serialVersionUID = 1L;private JComboBox comboBox;public static void main(String args) new UseCase1();public UseCase1() super();setVisible(true);setSize(200,150);setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);comboBox = new JComboBox();comboBox.addItem(红);comboBox.addItem(黄);comboBox.addItem(蓝);comboBox.addItem(黑);getContentPane().add(comboBox, BorderLayout.NORTH);final JPanel panel = new JPanel();getContentPane().add(panel, BorderLayout.CENTER);final JCheckBox checkBox = new JCheckBox();checkBox.setText(男);panel.add(checkBox);final JCheckBox checkBox_1 = new JCheckBox();checkBox_1.setText(女);panel.add(checkBox_1);final JPanel panel_1 = new JPanel();getContentPane().add(panel_1, BorderLayout.SOUTH);final JButton okButton = new JButton();okButton.setText(确定);panel_1.add(okButton);final JButton button_1 = new JButton();button_1.setText(取消);panel_1.add(button_1);13.2package com.lzw;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class UseCase2 extends JFrame/* * */private static final long serialVersionUID = 1L;private String contents=列表1,列表2,列表3,列表4,列表5;private JComboBox jc=new JComboBox();private JButton jb=new JButton(提交);int count=0;public UseCase2() setSize(200, 100);setVisible(true);setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);Container cp=getContentPane();cp.setLayout(new FlowLayout();cp.add(jc);cp.add(jb);jb.addActionListener(new ActionListener()public void actionPerformed(ActionEvent arg0) if(countcontents.length)jc.addItem(contentscount+););public static void main(String args) new UseCase2();13.3package com.lzw;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class UseCase3 extends JFrame/* * */private static final long serialVersionUID = 1L;public UseCase3()setVisible(true);setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);setTitle(登录窗体);setBounds(300, 200, 300, 150);Container cp=getContentPane();cp.setLayout(null);JLabel jl=new JLabel(用户名:);jl.setBounds(10, 10, 200, 18);final JTextField name=new JTextField();name.setBounds(80, 10, 150, 18);JLabel jl2=new JLabel(密码:);jl2.setBounds(10, 50, 200, 18);final JPasswordField password=new JPasswordField();password.setBounds(80, 50, 150, 18);cp.add(jl);cp.add(name);cp.add(jl2);cp.add(password);JButton jb=new JButton(确定);jb.addActionListener(new ActionListener()public void actionPerformed(ActionEvent arg0) if(name.getText().trim().length()=0|new String(password.getPassword().trim().length()=0)JOptionPane.showMessageDialog(null, 用户名密码不允许为空);return;if(name.getText().trim().equals(mr)&new String(password.getPassword().trim().equals(mrsoft)JOptionPane.showMessageDialog(null, 登录成功);elseJOptionPane.showMessageDialog(null, 用户名或密码错误););jb.setBounds(80, 80, 60, 18);cp.add(jb);final JButton button = new JButton();button.setText(重置);button.addActionListener(new ActionListener()public void actionPerformed(ActionEvent arg0) / TODO 自动生成方法存根name.setText();password.setText(););button.setBounds(150, 80, 60, 18);getContentPane().add(button);public static void main(String args) new UseCase3();14.1import java.util.*;public class Text public static void main(String args) List list = new LinkedList();for(int i = 1 ;i=100;i+)list.add(new Integer(i);list.remove(list.get(10);System.out.println(ok);14.2import java.util.*;public class Text public static void main(String args) Set set = new HashSet(); /HashSet是Set的子接口 set.add(a); set.add(c); set.add(A); set.add(a); set.add(C); List list = new ArrayL
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 阀门市场前景预测与采购成本控制策略研究报告
- 2025年减速器行业现状分析与前景研究报告
- 净水剂项目可行性研究报告范文
- 切片性能评估-洞察及研究
- 湖泊营养盐污染溯源-洞察及研究
- 声音特征性格分析-洞察及研究
- 基于人工智能技术的智能仓储管理终端系统研发与应用实践
- 公共空间功能设计研究
- 致密油藏水平井压裂技术优化与产量预测研究
- 智能家居行业的投资价值评估
- 《精益生产培训》课件
- 5S改善图片课件
- 纪检干部心理培训课件模板
- 胃健康知识科普
- 《红楼梦》中的爱情观与婚姻制度的评析
- 华中师大一附中2024届生物高二第二学期期末统考模拟试题含解析
- 中国中小学生积极心理品质量表心理课之后
- 新制度经济学复习资料
- 永久供电施工方案
- 热管理技术详述
- 应急演练评估表、评价表、评审表(模板)
评论
0/150
提交评论