java期末整理

上传人:第*** 文档编号:34041654 上传时间:2018-02-20 格式:DOC 页数:8 大小:67.50KB
返回 下载 相关 举报
java期末整理_第1页
第1页 / 共8页
java期末整理_第2页
第2页 / 共8页
java期末整理_第3页
第3页 / 共8页
java期末整理_第4页
第4页 / 共8页
java期末整理_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《java期末整理》由会员分享,可在线阅读,更多相关《java期末整理(8页珍藏版)》请在金锄头文库上搜索。

1、Java期末复习汇总1键盘输入判断奇偶.package jxz;import java.io.*;public class panduan public static void main(String args) String s=;System.out.println(请输入数字);try/*大括号里面必考 */BufferedReader br=new BufferedReader(new InputStreamReader(System.in);s=br.readLine();catch(IOException e)int x=Integer.parseInt(s);if(x%2=0)S

2、ystem.out.println(even);elseSystem.out.println(odd);2.从文本框得到一个整数和如何关闭窗口 窗体的实现 标签按钮 课本 177 例题 11-1:未做int 数学 = Integer.parseInt(txt.getText(); /txt 为文本框3.加密:把字母改为往后四个数ch=str.char.Ati;ai=(char)ch+4;4.连接 access 数据库那几行代码public class Datebase public static void main(String args) String url = jdbc:odbc:Dat

3、abase1;try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch (java.lang.ClassNotFoundException e) System.err.println(e.getMessage();try Connection con = DriverManager.getConnection(url, , null);System.out.println(Connection succeed!);con.close(); catch (SQLException ex) System.out.println(Message:

4、+ ex.getMessage();5.输入流BufferedReader br=new BufferedReader(new InputStreamReader(System.in);s=br.readLine();6.student 类有学号,姓名,年龄 存一个数组中public class student int number; String name; int age; int i;public student(int number,int age,String name)this.number=number;this.age=age;this.name=name;public Str

5、ing toString()return 学号: +number+,年龄:+ age+,姓名:+name;public static void main(String args) student s1=new student(1,18,张三);student s2=new student(4,22,李四);student s3=new student(7,21,王五);student s4=new student(3,26,马六);student s=s1,s2,s3,s4;System.out.println(班级人员名单:);for(int i=0;i20)System.out.print

6、ln(si);7.定义接口实现面积方法 即定义接口 Shape,其中包括一个方法 size(),设计矩形,圆,圆柱体等尅类实现 Shape 接口,其 size()方法表示计算矩形面积,圆面积,圆柱体体积。分别创建代表矩形,圆,圆柱体的 3 个对象存入一个 Shape 类型的数组中,并通过调用 size()方法将数组中各类图形的大小输出。清单:package jxz;interface Shapedouble size();class Rectangle implements Shape private int x;private int y;public Rectangle(int x, in

7、t y) this.x = x;this.y = y;public double size()return x*y;class Circle implements Shapeprivate double r;public Circle(double r)this.r=r;public double size()return 3.14*r*r;class Cylinder implements Shapeprivate Circle c;private double h;public Cylinder(Circle c,double h)this.c=c;this.h=h;public doub

8、le size()return c.size()*h;public class Java public static void main(String args)Shape s=new Shape3;s0=new Rectangle(5, 6);s1=new Circle(47);s2=new Cylinder(new Circle(20),5);for (int z=0;z=65&c=97&c=122) charnum+;System.out.println(您输入的字符串中字母的个数为: +charnum);/将单词 the 替换成 a,并输出结果k=a.indexOf(the);if(k

9、=-1) System.out.println(您输入的字符串中没有 the 子串。 );elseSystem.out.println(将 the 替换成 a 后的字符串为:+a.replaceAll(the,a);/找出所有的数字串for(int i=0;ia.length();i+)char ch=a.charAt(i);if(Character.isDigit(ch)digit.append(ch);isDigit=true;elseif(isDigit)digit.append(,);isDigit=false;String x=digit.toString().split(,);Sy

10、stem.out.println(共有 +x.length+个数字串: );for(int n=0;nx.length;n+)System.out.print(xn+ );复习下 继承和多态 构造方法在类继承中的作用;方法的重载和方法的覆盖10.图形用户界面编程gbc.gridx = 3;gbc.gridy = 8;/这两行根据实际情况变化/*这三行为核心代码 网格块布局 需要有约束对象GridBagConstraints */GridBagLayout gb = new GridBagLayout();this.setLayout(gb);GridBagConstraints gbc = n

11、ew GridBagConstraints();import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;public class zhuce extends JFrame implements ActionListener private JLabel lb1, lb2;/账号、密码private JTextField t1; /账号文本框private JPasswordField t2; /密码文本框private JButton b1, b2, b3; /确定、取消按钮public

12、zhuce() super(用户注册 );setSize(500,500);lb1 = new JLabel(账号 );lb2 = new JLabel(密码 );t1 = new JTextField(10);t2 = new JPasswordField(10);b1 = new JButton(确定 );b2 = new JButton(取消 );GridBagLayout gb = new GridBagLayout();this.setLayout(gb);GridBagConstraints gbc = new GridBagConstraints();gbc.gridx = 3;

13、gbc.gridy = 8;gbc.gridwidth = 2;gbc.gridheight = 1;this.add(lb1, gbc);gbc.gridx = 5;gbc.gridy = 8;gbc.gridwidth = 8;gbc.gridheight = 1;this.add(t1, gbc);gbc.gridx = 3;gbc.gridy = 9;gbc.gridwidth = 2;gbc.gridheight = 1;this.add(lb2, gbc);gbc.gridx = 5;gbc.gridy = 9;gbc.gridwidth = 8;gbc.gridheight =

14、1;this.add(t2, gbc);gbc.gridx = 6;gbc.gridy = 10;gbc.gridwidth = 2;gbc.gridheight = 1;this.add(b1, gbc);gbc.gridx = 11;gbc.gridy = 10;gbc.gridwidth = 2;gbc.gridheight = 1;this.add(b2, gbc);b1.addActionListener(this);b2.addActionListener(this);setVisible(true);public void actionPerformed(ActionEvent e) if(e.getSource() = b1) JOptionPane.showMessageDialog(null, 注册成功);if(e.getSource() = b2) this.dispose();public static void main(String args)new zhuce();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号