资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java期末代码编程题 java代码题目和答案

java面向对象程序设计期末考试编程题!急!!!

===============================第一题==============================

创新互联专注于璧山网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供璧山营销型网站建设,璧山网站制作、璧山网页设计、璧山网站官网定制、小程序制作服务,打造璧山网络公司原创品牌,更为您提供璧山网站排名全网营销落地服务。

import java.applet.Applet;

import java.awt.Color;

import java.awt.Label;

public class test extends Applet {

private Label label;

@Override

public void init() {

label=new Label("欢迎来到java世界!");

label.setBackground(Color.BLUE);

setBackground(Color.PINK);

add(label);

}

}

===============================第二题==============================

因为没图,所以自己设计的界面首宽局..

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

public class test implements ActionListener {

private JFrame frame;

private JLabel label;

private JTextArea jt;

private JScrollPane jsp;

private JButton show;

public test() {

frame=new JFrame("Test");

label=new JLabel("巧乎显示内者让容");

jt=new JTextArea(10,20);

jsp=new JScrollPane(jt);

show = new JButton("显示给定内容");

JPanel panel=new JPanel();

panel.add(label);

panel.add(show);

frame.add(jsp,BorderLayout.NORTH);

frame.add(panel,BorderLayout.SOUTH);

show.addActionListener(this);

show();

}

public void show(){

frame.setLocation(200, 200);

frame.setSize(300, 260);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

@Override

public void actionPerformed(ActionEvent e) {

label.setText(jt.getText());

}

public static void main(String[] args) {

new test().show();

}

}

5道简单的JAVA编程题(高分悬赏)

很详细的帮你写下,呵呵,所以要给分哦!

1、

(1)源程序如下:

public class One {

public static void main(String[] args) {

String name = "张三";

int age = 23;

char sex = '男';

String myclass = "某某专业2班";

System.out.println("姓名:" + name);

System.out.println("姓名:" + age);

System.out.println("姓名:" + sex);

System.out.println("姓名:" + myclass);

}

}

(2)

编写完程序的后缀名是.java,如本题,文件名就是One.java。

开始\运行\cmd,进入“命令提示符窗口”,然后用javac编译器编译.java文件,语句:javac One.java。

(3)

编译成功后,生成的文件名后缀是.class,叫做字节码文件。再用java解释器冲搜纳来运行改程序,语句:java One

2、编写程序,输出1到100间的所有偶数

(1)for语句

public class Two1 {

public static void main(String[] args) {

for(int i=2;i=100;i+=2)

System.out.println(i);

}

}

(2)while语句

public class Two2 {

public static void main(String[] args) {

int i = 2;

while (i = 100) {

System.out.println(i);

i += 2;

}

}

}

(3)do…while语漏芹句

public class Two3 {

public static void main(String[] args) {

int i = 2;

do {

System.out.println(i);

i += 2;

}while(i=100);

}

}

3、编写程序,从10个数当中找出最大散没值。

(1)for循环

import java.util.*;

public class Three1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int number;

int max = 0;

for (int i = 0; i 10; i++) {

System.out.print("输入第" + (i + 1) + "个数:");

number = input.nextInt();

if (max number)

max = number;

}

System.out.println("最大值:" + max);

}

}

(2)while语句

import java.util.*;

public class Three2 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int number;

int max = 0;

int i = 0;

while (i 10) {

System.out.print("输入第" + (i + 1) + "个数:");

number = input.nextInt();

if (max number)

max = number;

i++;

}

System.out.println("最大值:" + max);

}

}

(3)do…while语句

import java.util.*;

public class Three3 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int number;

int max = 0;

int i = 0;

do {

System.out.print("输入第" + (i + 1) + "个数:");

number = input.nextInt();

if (max number)

max = number;

i++;

}while(i10);

System.out.println("最大值:" + max);

}

}

4、编写程序,计算从1到100之间的奇数之和。

(1)for循环

public class Four1 {

public static void main(String[] args) {

int sum=0;

for(int i = 1;i=100;i+=2){

sum+=i;

}

System.out.println("1~100间奇数和:" + sum);

}

}

(2)while语句

public class Four2 {

public static void main(String[] args) {

int sum = 0;

int i = 1;

while (i = 100) {

sum += i;

i += 2;

}

System.out.println("1~100间奇数和:" + sum);

}

}

(3)do…while语句

public class Four3 {

public static void main(String[] args) {

int sum = 0;

int i = 1;

do {

sum += i;

i += 2;

} while (i = 100);

System.out.println("1~100间奇数和:" + sum);

}

}

5、

(1)什么是类的继承?什么是父类?什么是子类?举例说明。

继承:是面向对象软件技术当中的一个概念。如果一个类A继承自另一个类B,就把这个A称为"B的子类",而把B称为"A的父类"。继承可以使得子类具有父类的各种属性和方法,而不需要再次编写相同的代码。在令子类继承父类的同时,可以重新定义某些属性,并重写某些方法,即覆盖父类的原有属性和方法,使其获得与父类不同的功能。另外,为子类追加新的属性和方法也是常见的做法。继承需要关键字extends。举例:

class A{}

class B extends A{}

//成员我就不写了,本例中,A是父类,B是子类。

(2)编写一个继承的程序。

class Person {

public String name;

public int age;

public char sex;

public Person(String n, int a, char s) {

name = n;

age = a;

sex = s;

}

public void output1() {

System.out.println("姓名:" + name + "\n年龄:" + age + "\n性别:" + sex);

}

}

class StudentPerson extends Person {

String school, department, subject, myclass;

public StudentPerson(String sc, String d, String su, String m, String n,

int a, char s) {

super(n, a, s);

school = sc;

department = d;

subject = su;

myclass = m;

}

public void output2() {

super.output1();

System.out.println("学校:" + school + "\n系别:" + department + "\n专业:"

+ subject + "\n班级:" + myclass);

}

}

public class Five2 {

public static void main(String[] args) {

StudentPerson StudentPersonDemo = new StudentPerson("某某大学", "某某系别",

" 某专业", "某某班级", " 张三", 23, '男');

StudentPersonDemo.output2();

}

}

java编程题,期末考试的题,跪求,求大佬编写一下

public class RunTest {

private static int[] arr = { 2, 5, 7, 1, 3, 4, 含哪卖6, 9, 8 };

public static void main(String[] args) {

System.out.println("原始:"+Arrays.toString(arr));

new Thread() {

public void run() {

StringBuilder sd=new StringBuilder();

for(int a:arr) {

sd.append(a+" ");

}

System.out.println("反转:["+sd.reverse()+" ]");

}

}.start();

new Thread() {

public void run() {

for (int i = 0; i  arr.length - 1; i++) {

for (int j = 0; j  arr.length - i - 1; j++) {

if (arr[j]  arr[j + 1]) {

int temp = arr[j];

arr[j] 缓销= 谈逗arr[j + 1];

arr[j + 1] = temp;

}

}

}

System.out.println("冒泡:"+Arrays.toString(arr));

}

}.start();

}

}


标题名称:Java期末代码编程题 java代码题目和答案
网址分享:http://cdkjz.cn/article/ddpcgii.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220