




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1.将矩阵行列互调并输出。public class ArrayExe public static void main(String args) int count1=1;int count2=0;int array=new int33; ArrayExe arr=new ArrayExe();/for(int i=0;iarray.length;i+)for(int j=0;jarrayi.length;j+)arrayij=count1+;System.out.println(原矩阵中元素:);arr.prin(array); for(int i=0;iarray.length;i+)for(int j=i;jarrayi.length;j+)count2=arrayij;arrayij=arrayji;arrayji=count2;System.out.println(行列互调后的结果:);arr.prin(array);/ public void prin(int array) int count=0;for(int i=0;iarray.length;i+)for(int j=0;jarrayi.length;j+) System.out.print(arrayij+t); count+; if(count%3=0) System.out.println(); System.out.println();2.计算购物结算,用户可以享受购物8折的优惠,请计算实际消费金额, (1)创建Java类Pay(2)在Pay.java文件中声明变量存储信息(3)计算总金额,消费总额 = 各商品的消费金额之和 * 折扣public class Paypublic static void main(String args) / TODO Auto-generated method stubfloat applePrice,orangePrice;int appleNum,orageNum;float appleAmount,orangeAmount;float amount;float discountAmount;/给变量赋值applePrice=2.5f; /float类型后加上forangePrice=3;appleNum=3;orageNum=2;amount=applePrice*appleNum+orangePrice*orageNum;discountAmount=amount*0.8f; /discountAmount是float类型,所以是.8fSystem.out.println(打折后的金额:+discountAmount);2. 打印购物小票并计算积分.import java.util.Scanner;public class Array2 public static void main(String args) int count;int array=new int10;int array2=new int10; for(count=0;count5;count+)Scanner input=new Scanner(System.in);System.out.print(请输入第+(count+1)+个会员的积分:); arraycount=input.nextInt(); System.out.println();System.out.println(序号tt历史积分tt最新积分);for(int i=0;i5 ;i+)array2i=arrayi+500;System.out.println(i+1)+tt+arrayi+tt+array2i);3.求110之间的所有偶数和(使用for循环)public class sum public static void main(String args) int countSum=0; for(int count=2;count=10;count+=2) countSum+=count; System.out.println(1-10之间偶数之和:ncountSum=+countSum);4. 依次录入同学学习JAVA的成绩,统计各个分数段的成绩的人数。import java.util.Scanner;public class javaGrade public static void main(String args) Scanner input=new Scanner(System.in);int count1=0,count2=0,count3=0,count4=0,count5=0,count6=0 ; System.out.println(输入所有JAVA成绩:);for(int i=0;i5;i+)int stb=input.nextInt();switch(stb/10)case 9:count1+; break;case 8:count2+; break;case 7:count3+; break;case 6:count4+; break;case 10:count5+; break; default:count6+; break;System.out.println(100分的人数:+count5);System.out.println(90-100分的人数:+count1);System.out.println(80-90分的人数:+count2);System.out.println(70-80分的人数:+count3);System.out.println(60-70分的人数:+count4);System.out.println(小于分的人数:+count6); 5. 以表格的形式输出笔购物金额及总金额 升序排列金额数据import java.util.Scanner;import java.util.Arrays;public class ArrayExe public static void main(String args) int count;double Price=new double5;double sum=0;/输入部分for(count=0;count5;count+)Scanner input=new Scanner(System.in);System.out.print(请输入第+(count+1)+笔购物金额:); Pricecount=input.nextDouble(); System.out.println();/输出部分System.out.println(序号tt金额(元);for(int i=0;i5 ;i+)System.out.println(i+1)+tt+Pricei);sum+=Pricei;System.out.println(总金额tt+sum);System.out.println();/表格输出部分Arrays.sort(Price);System.out.println(-);System.out.print(|序号t|);for(int i=0;i5;i+)System.out.print(i+1)+t|);System.out.print(总金额+t|);System.out.println();System.out.println(-);System.out.print(|金额t|);for(int i=0;i0&age100) this.age=age; else throw new Exception(年龄必须在1-100之间); public void printAge() System.out.println(年龄:+this.age); public class testPerson public static void main(String args) Person person=new Person(); try person.setAge(101); person.printAge(); catch(Exception e) e.printStackTrace(); public class testPerson public static void main(String args) Person person=new Person(); try person.setAge(101); person.printAge(); catch(Exception e) e.printStackTrace(); public class testPerson public static void main(String args) Person person=new Person(); try person.setAge(101); person.printAge(); catch(Exception e) e.printStackTrace(); (2)按照控制台提示输入13之间任一个数字,程序将输出相应的课程名称根据键盘输入进行判断。如果输入正确,输出对应课程名称。如果输入错误,给出错误提示不管输入是否正确,均输出“欢迎提出建议”语句import java.util.Scanner;public class Courses public static void main(String args) int n; try Scanner input=new Scanner(System.in); System.out.print(请输入数字:1,2或3:); n=input.nextInt(); switch(n) case 1: System.out.println(英语); break; case 2: System.out.println(数学); break; case 3: System.out.println(语文); break; default: System.out.println(必须使用1-3); catch(Exception e) System.err.println(发生异常,必须使用1-3); finally System.out.println(欢迎提出建议); 8事件的操作import java.awt.*;import javax.swing.*;import java.awt.event.*;public class FirstFrame public static class moniter1 implements ActionListener public void actionPerformed(ActionEvent arg0) System.out.print(我被击中了); public static class moniter2 implements ActionListener public void actionPerformed(ActionEvent arg0) System.out.print(你被击中了); public static void main(String args) / TODO Auto-generated method stub JFrame jf = new JFrame(); jf.setTitle(this is my first Frame!); jf.setBounds(10,10,400,400); jf.setVisible(true); GridLayout gridLayout=new GridLayout(3,3,10,20); jf.setLayout(gridLayout); JButton btn1 = new JButton(我); btn1.addActionListener(new moniter1(); jf.add(btn1); JButton btn2 = new JButton(你); btn2.addActionListener(new moniter2(); jf.add(btn2); jf.add(new JButton(3); jf.add(new JButton(4); jf.add(new JButton(5); jf.add(new JButton(6); jf.add(new JButton(7); jf.add(new JButton(8); jf.add(new JButton(9); jf.validate(); 控件综合实验import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.print.DocFlavor.URL;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.EtchedBorder;import javax.swing.border.TitledBorder;SuppressWarnings( serial, unused )public class SwingRegister extends JFrame public SwingRegister() this.init();public void init() this.setTitle(用户注册);this.setBounds(100, 100, 340,600);/this.createUI();this.setVisible(true);this.setDefaultCloseOperation(EXIT_ON_CLOSE); JTextField nameTxt = new JTextField(); JPasswordField pwd = new JPasswordField(); JPanel panel = new JPanel();public void createUI() / 添加边框Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);TitledBorder tBorder = BorderFactory.createTitledBorder(border, 注册面板,TitledBorder.CENTER, TitledBorder.TOP);panel.setBorder(tBorder);panel.setLayout(null);this.add(panel);/密码JLabel pwdLbl = new JLabel(输入密码:);pwdLbl.setBounds(10, 80, 60, 25);panel.add(pwdLbl);pwd.setBounds(80, 80, 120, 22);panel.add(pwd);/性别JLabel genderLbl = new JLabel(性别:);genderLbl.setBounds(10, 110, 60, 25);panel.add(genderLbl);ButtonGroup group = new ButtonGroup();JRadioButton fRdo = new JRadioButton(男, true);fRdo.setBounds(80, 110, 50, 25);group.add(fRdo);JRadioButton mRdo = new JRadioButton(女, false);mRdo.setBounds(140, 110, 50, 25);group.add(mRdo);panel.add(fRdo);panel.add(mRdo);/姓名JLabel nameLbl = new JLabel(输入姓名:);nameLbl.setBounds(10, 50, 60, 25);panel.add(nameLbl);/final JTextField nameTxt = new JTextField();nameTxt.setBounds(80, 50, 120, 22);panel.add(nameTxt);/学历JLabel ediLbl = new JLabel(学历:);ediLbl.setBounds(10, 140, 60, 25);panel.add(ediLbl);/下拉列表JComboBox edicbo = new JComboBox();edicbo.addItem(高中);edicbo.addItem(大专);edicbo.addItem(本科);edicbo.addItem(其它);edicbo.setBounds(80, 140, 80, 22);panel.add(edicbo);/爱好JLabel hobbyLbl = new JLabel(爱好:);hobbyLbl.setBounds(10, 170, 60, 25);panel.add(hobbyLbl);/复选框JCheckBox hobbyChk = new JCheckBox(睡觉);hobbyChk.setBounds(80, 170, 60, 25);panel.add(hobbyChk);JCheckBox hobbyChk2 = new JCheckBox(运动, true);hobbyChk2.setBounds(150, 170, 60, 25);panel.add(hobbyChk2);JCheckBox hobbyChk3 = new JCheckBox(爬山);hobbyChk3.setBounds(220, 170, 60, 25);panel.add(hobbyChk3);/自我介绍JLabel intrLbl = new JLabel(自我介绍:);intrLbl.setBounds(10, 200, 60, 25);panel.add(intrLbl);/Swing中,文本域默认是不带滚动条的,必须放置在JScrollPane中,才会滚动条JTextArea intrArea = new JTextArea();JScrollPane scrollPane = new JScrollPane(intrArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);scrollPane.setBounds(20, 230, 240, 110);panel.add(scrollPane);/放置图片JLabel imgLbl = new JLabel();imgLbl.setBounds(5, 350, 324, 47);panel.add(imgLbl); Object url = this.getClass().getResource(149.gif);/Icon icon = new ImageIcon();imgLbl.setIcon(icon);/按钮JButton btn = new JButton( 提交 );btn.setBounds(50, 420, 70, 22);btn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) /* 参数1: 父组件 参数2: 提示信息 参数3: 标题信息 * 参数4: 指定按钮类型 参数5: 指定图标类型 * 返回值:用户所选选项的整数*/int option = JOptionPane.showConfirmDialog(null, 你确定提交吗?,提交提示, JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);if (option = JOptionPane.OK_OPTION) System.out.println(ok,submit!); else System.out.println(no, cancel););btn.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) String str1=姓名:;str1=str1+nameTxt.getText();str1=str1+密码:; str1=str1+pwd.getPassword().toString(); JTextField answerTxt = new JTextField();answerTxt.setBounds(80, 350,180, 22);answerTxt.setText(str1);panel.add(answerTxt););panel.add(btn);JButton btn2 = new JButton( 重置 );btn2.setBounds(150, 420, 70, 22);panel.add(btn2);btn2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) /重置处理代码.);/JLabel answerLabel = new JLabel(个人信息);answerLabel.setBounds(10, 350,80, 25);panel.add(answerLabel); public static void main(String args) new SwingRegister(); 11.(1)创建一个文件并输出文件的相关信息(2) 在以上文件中写入I am a student!(3) 使用缓冲区技术完成以上操作import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;public class FileTest public static void main(String args) /1.创建一个文件并输出文件的相关信息 File file=new File(myText.txt);/创建文件 if(file.exists() file.delete(); else try file.createNewFile(); catch(Exception e) e.printStackTrace(); String name=file.ge
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电子调温电炉培训
- 物业工程安全培训
- 2026届四川省绵阳地区化学九上期中学业水平测试模拟试题含解析
- 2026届北京市丰台区名校九年级化学第一学期期中统考试题含解析
- 传统木工技术概述
- 2026届重庆市南川区部分学校化学九上期末达标检测模拟试题含解析
- 2026届浙江省部分地区化学九年级第一学期期中学业质量监测模拟试题含解析
- 四川省成都市温江区第二区2026届化学九上期中质量检测模拟试题含解析
- 地生教学工作总结
- 湖北省武汉市江汉区2026届九上化学期中复习检测模拟试题含解析
- 2025年山东省高考地理试卷真题(含答案解析)
- 木工课堂安全管理制度
- 全屋定制合同赔付协议书
- 【《基于Matlab的电力系统电压稳定L指标计算与灵敏度分析》18000字】
- 2025-2030中国中药饮片行业发展分析及发展战略研究报告
- 肠菌移植治疗炎症性肠病专家共识(2025版)解读
- 小班语言活动《笑嘻嘻》
- NHSS系列钢丝绳手扳葫芦
- 运动康复项目介绍
- 英语横向课题申报书
- 2025中国地中海贫血祛铁治疗指南解读
评论
0/150
提交评论