Java编程题目及答案.doc_第1页
Java编程题目及答案.doc_第2页
Java编程题目及答案.doc_第3页
Java编程题目及答案.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1. 从键盘输入10个整数,存储到一个数组中,然后找出其中最大值和最小值,并给出他们在数组中的下标。import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class jfa public static void main(String args) int Numbers = new int10;BufferedReader r = new BufferedReader(new InputStreamReader(System.in);try for (int i=0;iNumbers.length; i+) Numbersi = Integer.parseInt(r.readLine(); catch(IOException e) int Max = Numbers0, Min = Numbers0;int MaxSubscript = 0, MinSubscript = 0;for (int i=1;i Max)Max = Numbersi;MaxSubscript = i;if (Numbersi Min) Min = Numbersi;MinSubscript = i;for (int i=0; i Numbers.length; i+)System.out.print(Numbersi + );System.out.print(n);System.out.println(最大的数字:+Max+下标:+MaxSubscript);System.out.println(最小的数字:+Min+下标:+MinSubscript);2. 最简单的Java程序(输出“你好”的Applet和Application程序)import java.awt.*;import java.applet.*;public class c1_1 extends Applet public void paint(Graphics g) g.drawString(“你好”,25,25);public class c1_2 public static void main(String args) System.out.println(“你好”);3. 计算圆的面积(Applet和Application)import java.awt.*;import java.applet.*;public class c2_1 extends Applet double cparea(double r) return Math.PI * r * r;public void paint(Graphics g) double b = 12;g.drawString(面积是:+cparea(b),25,25);public class c2_2 static double cparea(double r) return Math.PI * r * r;public static void main(String args) double b = 12;System.out.println(面积是:+cparea(b);import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class c2_2 static double cparea(double r) return Math.PI * r * r;public static void main(String args) throws IOException BufferedReader x = new BufferedReader(new InputStreamReader(System.in);System.out.println(面积是:+cparea(Double.parseDouble(x.readLine();4. 设定5个字符串并只打印那些以字母“b”开头的串。P165 7.5public class j7_5 public static void main(String args) String s = new String5;s0 = GHASFDSGSERGFFHGFb;s1 = bdfGDFDFGfdgdfgfd;s2 = SAFSA$%#%#$;s3 = abaaaaaaaasdad;s4 = btgsgtetesrhyrsyr;for (int i = 0; i s.length; i+) if (si.startsWith(b) System.out.println(si);5. 创建一个链表Lf,创建三个结点N1、N2、N3,按下列要求将三个结点放入链表Lf中,编程实现:(1) 将N2作为链表的头结点;(2) 将N1作为链表的尾结点;(3) 将N3作为链表的中间结点;(4) 打印链表Lf的所有结点。class Node int data; Node next; Node(int i) data= i; next=null;class List private Node head,tail; String Lname; List(String str) Lname=str; head = null; tail = null; void addTail(Node obj) if (head = null) head = obj;tail=obj; else tail.next = obj;tail=obj; void addHead(Node obj) if (head = null) head = obj; tail=obj; else obj.next = head; head = obj; void ShowAll() Node p = head; while (p != null) System.out.println(p.data); p = p.next; public class j8_4 public static void main(String args) Node n1 = new Node(1), n2 = new Node(2), n3 = new Node(3); List l = new List(Lf); l.addHead(n2); l.addTail(n3) ; l.addTail(n1); l.ShowAll(); 6. 输出自己的名字、班级及学号,要求名字设置为24号黑体,班级及学号设置为16号加粗斜宋体。P214 9.7import java.awt.*;import java.applet.*;public class j9_7 extends Applet public void paint(Graphics g) Graphics2D g2 = (Graphics2D)g; g2.setFont(new Font(黑体, Font.PLAIN, 24); g2.drawString(姓名:张三t, 25, 35); g2.setFont(new Font(宋体, Font.BOLD + Font.ITALIC, 16); g2.drawString(班级:计科0601t, 25, 60); g2.drawString(学号: 0000001t, 25, 85); 7. 建立一个班级下拉式列表,列表项中有101班、102班、103班、104班和105班,当点击某个选项时,将这个选项的内容复制到按钮文本中。要求字体大小为24号,颜色为红色。import java.awt.*;import java.awt.event.*;import javax.swing.*;public class j6_3 extends JFrame JPanel contentPane;JComboBox combo;JButton button = new JButton();public j6_3() enableEvents(AWTEvent.WINDOW_EVENT_MASK); try jbInit(); catch(Exception e) e.printStackTrace(); this.setVisible(true); public static void main(String args) new j6_3();private void jbInit() throws Exception contentPane = (JPanel)this.getContentPane();contentPane.setLayout(new FlowLayout(FlowLayout.LEFT);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setSize(new Dimension(400, 300);combo = new JComboBox();combo.addItemListener(new ItemList(); combo.addItem(101班); combo.addItem(102班); combo.addItem(103班); combo.addItem(104班); combo.addItem(105班); contentPane.add(combo); contentPane.add(button);class ItemList imple

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论