新聞中心
java面向?qū)ο蟪绦蛟O(shè)計(jì)期末考試編程題!急!!!
===============================第一題==============================
創(chuàng)新互聯(lián)專注于璧山網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供璧山營(yíng)銷型網(wǎng)站建設(shè),璧山網(wǎng)站制作、璧山網(wǎng)頁(yè)設(shè)計(jì)、璧山網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造璧山網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供璧山網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
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("歡迎來(lái)到j(luò)ava世界!");
label.setBackground(Color.BLUE);
setBackground(Color.PINK);
add(label);
}
}
===============================第二題==============================
因?yàn)闆](méi)圖,所以自己設(shè)計(jì)的界面首寬局..
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("巧乎顯示內(nèi)者讓容");
jt=new JTextArea(10,20);
jsp=new JScrollPane(jt);
show = new JButton("顯示給定內(nèi)容");
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道簡(jiǎn)單的JAVA編程題(高分懸賞)
很詳細(xì)的幫你寫下,呵呵,所以要給分哦!
1、
(1)源程序如下:
public class One {
public static void main(String[] args) {
String name = "張三";
int age = 23;
char sex = '男';
String myclass = "某某專業(yè)2班";
System.out.println("姓名:" + name);
System.out.println("姓名:" + age);
System.out.println("姓名:" + sex);
System.out.println("姓名:" + myclass);
}
}
(2)
編寫完程序的后綴名是.java,如本題,文件名就是One.java。
開(kāi)始\運(yùn)行\(zhòng)cmd,進(jìn)入“命令提示符窗口”,然后用javac編譯器編譯.java文件,語(yǔ)句:javac One.java。
(3)
編譯成功后,生成的文件名后綴是.class,叫做字節(jié)碼文件。再用java解釋器沖搜納來(lái)運(yùn)行改程序,語(yǔ)句:java One
2、編寫程序,輸出1到100間的所有偶數(shù)
(1)for語(yǔ)句
public class Two1 {
public static void main(String[] args) {
for(int i=2;i=100;i+=2)
System.out.println(i);
}
}
(2)while語(yǔ)句
public class Two2 {
public static void main(String[] args) {
int i = 2;
while (i = 100) {
System.out.println(i);
i += 2;
}
}
}
(3)do…while語(yǔ)漏芹句
public class Two3 {
public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i=100);
}
}
3、編寫程序,從10個(gè)數(shù)當(dāng)中找出最大散沒(méi)值。
(1)for循環(huán)
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) + "個(gè)數(shù):");
number = input.nextInt();
if (max number)
max = number;
}
System.out.println("最大值:" + max);
}
}
(2)while語(yǔ)句
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) + "個(gè)數(shù):");
number = input.nextInt();
if (max number)
max = number;
i++;
}
System.out.println("最大值:" + max);
}
}
(3)do…while語(yǔ)句
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) + "個(gè)數(shù):");
number = input.nextInt();
if (max number)
max = number;
i++;
}while(i10);
System.out.println("最大值:" + max);
}
}
4、編寫程序,計(jì)算從1到100之間的奇數(shù)之和。
(1)for循環(huán)
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間奇數(shù)和:" + sum);
}
}
(2)while語(yǔ)句
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間奇數(shù)和:" + sum);
}
}
(3)do…while語(yǔ)句
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間奇數(shù)和:" + sum);
}
}
5、
(1)什么是類的繼承?什么是父類?什么是子類?舉例說(shuō)明。
繼承:是面向?qū)ο筌浖夹g(shù)當(dāng)中的一個(gè)概念。如果一個(gè)類A繼承自另一個(gè)類B,就把這個(gè)A稱為"B的子類",而把B稱為"A的父類"。繼承可以使得子類具有父類的各種屬性和方法,而不需要再次編寫相同的代碼。在令子類繼承父類的同時(shí),可以重新定義某些屬性,并重寫某些方法,即覆蓋父類的原有屬性和方法,使其獲得與父類不同的功能。另外,為子類追加新的屬性和方法也是常見(jiàn)的做法。繼承需要關(guān)鍵字extends。舉例:
class A{}
class B extends A{}
//成員我就不寫了,本例中,A是父類,B是子類。
(2)編寫一個(gè)繼承的程序。
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("學(xué)校:" + school + "\n系別:" + department + "\n專業(yè):"
+ subject + "\n班級(jí):" + myclass);
}
}
public class Five2 {
public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson("某某大學(xué)", "某某系別",
" 某專業(yè)", "某某班級(jí)", " 張三", 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("反轉(zhuǎn):["+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代碼題目和答案
標(biāo)題來(lái)源:http://ef60e0e.cn/article/ddpcgii.html