import java.util.Random;
創(chuàng)新互聯(lián)建站為企業(yè)級客戶提高一站式互聯(lián)網+設計服務,主要包括成都網站制作、成都網站設計、app軟件定制開發(fā)、重慶小程序開發(fā)公司、宣傳片制作、LOGO設計等,幫助客戶快速提升營銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經驗豐富的經驗,可以確保每一個作品的質量和創(chuàng)作周期,同時每年都有很多新員工加入,為我們帶來大量新的創(chuàng)意。
import java.util.Scanner;
public class MaxNumber {
private static Scanner input = new Scanner(System.in); // 實例控制臺輸入類
public static void main(String[] args) {
/*
* 第一步, 按照題目要求 , 我們需要用戶輸入 10 個數字
*/
int[] numberArray = new int[10]; // 我們先定義一個 可以裝 10 個數字的數組
int choose = chooseMode(); // 我加了一個選擇模式的函數
if (choose == 1) { // 用戶手工輸入
for (int i = 0; i numberArray.length; i++) { // 循環(huán)輸入
System.out.print("請定義第 '" + (i + 1) + "' 個數字:"); // 輸出控制臺提示
numberArray[i] = input.nextInt(); // 要求輸入, 并存儲到數組變量里
}
} else { // 計算機隨機生成
Random random = new Random(); // 隨機數類
int tempNumber = 0 ; // 臨時變量
for (int i = 0; i numberArray.length; i++) { // 計算機生成
tempNumber = random.nextInt(100) + 1; // 隨機生成 1 - 100 的數
System.out.println("計算機生成的第 '" + (i + 1) + "' 個數字是:" + tempNumber);
numberArray[i] = tempNumber; // 賦值
}
}
/*
* 第二步 , 找這 10 個數當中 , 最大的數.
*/
int maxNumber = 0; // 定義一個變量接收最大的數
for (int i = 0; i numberArray.length; i++) { // 循環(huán)尋找
/*
* 循環(huán)比對, 一個接一個的, 如果 '當前數' , 比我們已經記錄的 '最大數' 還大, 那我們就把當前數 賦給 最大數
*/
if (numberArray[i] maxNumber) {
maxNumber = numberArray[i];
}
}
System.out.println("其中最大的數是:" + maxNumber); // 輸出結果
}
/**
* 選擇模式方法
* @return 返回選擇的模式的編號
*/
public static int chooseMode() {
System.out.println("------------ 選擇模式 ------------");
System.out.println("\t1. 用戶輸入十個數字");
System.out.println("\t2. 計算機隨機產生十個數字");
System.out.print("請選擇:");
return input.nextInt(); // 輸入, 返回
}
/*
* 其中包函的知識有: 控制臺輸入, 輸出 , 數組 , 循環(huán) , if 判斷語句
*/
}
最后:
希望能幫到你,如果有什么問題可以 Hi 我,
看到樓主花了怎么多耐心,寫了怎么多判斷,也可以見得樓主確實用心了,
只是沒找到方法。
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JButton;
public class Stmessege {
Font font = new Font("楷體", Font.BOLD, 18);
private Frame m = new Frame("登陸成功界面");
protected Window f;
public Stmessege() {
m.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
m.setVisible(false);
m.dispose();
System.exit(0);
}
});
m.setSize(460, 360);
m.setBackground(Color.green);
m.setLayout(null);
m.setLocationRelativeTo(null);
Label l0 = new Label("管理員信息");
Font font1 = new Font("楷體", Font.BOLD, 32);
l0.setForeground(Color.blue);
l0.setSize(180, 50);
l0.setLocation(150, 30);
l0.setFont(font1);
final Label l1 = new Label("姓名:");
l1.setSize(60, 20);
l1.setLocation(10, 100);
l1.setFont(font);
TextField tf1 = new TextField("黃朋");
tf1.setForeground(Color.blue);
tf1.setBackground(Color.white);
tf1.setSize(50, 20);
tf1.setLocation(70, 100);
final Label l2 = new Label("學號:");
l2.setSize(60, 20);
l2.setLocation(140, 100);
l2.setFont(font);
TextField tf2 = new TextField("111265");
tf2.setForeground(Color.blue);
tf2.setBackground(Color.white);
tf2.setSize(60, 20);
tf2.setLocation(190, 100);
final Label l3 = new Label("性別:");
l3.setSize(60, 20);
l3.setLocation(280, 100);
l3.setFont(font);
TextField tf3 = new TextField("男");
tf3.setForeground(Color.blue);
tf3.setBackground(Color.white);
tf3.setSize(40, 20);
tf3.setLocation(360, 100);
final Label l4 = new Label("班級:");
l4.setSize(60, 20);
l4.setLocation(10, 170);
l4.setFont(font);
TextField tf4 = new TextField("611231");
tf4.setForeground(Color.blue);
tf4.setBackground(Color.white);
tf4.setSize(60, 20);
tf4.setLocation(67, 170);
final Label l5 = new Label("系別:");
l5.setSize(60, 20);
l5.setLocation(140, 170);
l5.setFont(font);
TextField tf5 = new TextField("計算機工程系");
tf5.setForeground(Color.blue);
tf5.setBackground(Color.white);
tf5.setSize(80, 20);
tf5.setLocation(200, 170);
final Label l6 = new Label("成績:");
l6.setSize(60, 20);
l6.setLocation(280, 170);
l6.setFont(font);
TextField tf6 = new TextField("95");
tf6.setForeground(Color.blue);
tf6.setBackground(Color.white);
tf6.setSize(40, 20);
tf6.setLocation(360, 170);
final Label l7 = new Label("專業(yè):");
l7.setSize(60, 20);
l7.setLocation(10, 230);
l7.setFont(font);
TextField tf7 = new TextField("軟件技術");
tf7.setForeground(Color.blue);
tf7.setBackground(Color.white);
tf7.setSize(60, 20);
tf7.setLocation(70, 230);
JButton btn1 = new JButton("添加");
btn1.setForeground(Color.blue);
btn1.setSize(80, 38);
btn1.setLocation(35, 300);
btn1.setFont(font);
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 插入();
m.setVisible(true);
}
});
JButton btn2 = new JButton("查詢學生學籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200, 38);
btn2.setLocation(135, 300);
btn2.setFont(font);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Stmessege1 f;
try {
f = new Stmessege1();
f.Stmessege11();
m.setVisible(true);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton btn3 = new JButton("刪除");
btn3.setForeground(Color.blue);
btn3.setSize(80, 38);
btn3.setLocation(350, 300);
btn3.setFont(font);
btn3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 刪除();
//f.setVisible(false);
m.setVisible(true);
}
});
JButton btn4 = new JButton("更新");
btn4.setForeground(Color.blue);
btn4.setSize(80, 38);
btn4.setLocation(200, 230);
btn4.setFont(font);
btn4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 更新();
m.setVisible(true);
}
});
m.add(l0);
m.add(l1);
m.add(tf1);
m.add(l2);
m.add(tf2);
m.add(l3);
m.add(tf3);
m.add(l4);
m.add(tf4);
m.add(l5);
m.add(tf5);
m.add(l6);
m.add(tf6);
m.add(l7);
m.add(tf7);
m.add(btn1);
m.add(btn2);
m.add(btn3);
m.add(btn4);
m.setVisible(true);
}
public static void main(String[] args) {
new Stmessege();
}
}
可以仿照我的做一下,希望采納,我才一級哦
采用mvc設計模式即可。設計用戶表,試題表,試卷表,考試表
然后系統(tǒng)分為教師和學生兩種角色
閱卷采用自動閱卷和手動閱卷兩種模式相結合
學生可以參加考試和查看成績
教師可以發(fā)布試題到指定班級和時間
使用緩存就可以了,把題目的id保存到緩存里面,具體的題目還是在數據庫里面,需要顯示的時候根據id去調取數據
shape接口
圓類
矩形類
三角形類1
三角形類2
測試類
public?class?RandomUtils?{
public?static?String?randomId(){
Random?random?=?new?Random();
StringBuilder?sb?=?new?StringBuilder();
for?(int?i?=?0;?i??6;?i++)?{
sb.append(random.nextInt(10));
}
return?sb.toString();
}
public?static?int?randomIntId(){
Random?random?=?new?Random();
StringBuilder?sb?=?new?StringBuilder();
for?(int?i?=?0;?i??6;?i++)?{
sb.append(random.nextInt(10));
}
return?Integer.parseInt(sb.toString());
}
public?static?String?randomName(){
String[]?name1?=?{"趙","錢","孫","李","周","吳","鄭","王","張","劉"};
String[]?name2?=?{"一","二","三","四","五","六","七","八","九","十"};
Random?random?=?new?Random();
StringBuilder?sb?=?new?StringBuilder();
sb.append(name1[random.nextInt(10)]);
sb.append(name2[random.nextInt(10)]);
sb.append(name2[random.nextInt(10)]);
return?sb.toString();
}
public?static?String?randomSex(){
Random?random?=?new?Random();
return?random.nextInt(4)/2==0?"男":"女";
}
public?static?int?randomAge(int?min,?int?max){
Random?random?=?new?Random();
return?random.nextInt(min)?+?max-min;
}
public?static?int?randomScore(){
Random?random?=?new?Random();
return?(int)(random.nextDouble()*100%100);
}
public?static?String?randomAddress(){
String[]?address1?=?{"商業(yè)","紅葉","安康","河南","長海","黃河","桐柏","科學","瑞達","花園"};
String[]?address2?=?{"東","南","西","北","中"};
String[]?address3?=?{"街","路","大道","巷"};
Random?random?=?new?Random();
StringBuilder?sb?=?new?StringBuilder();
sb.append(address1[random.nextInt(10)]);
sb.append(address2[random.nextInt(5)]);
sb.append(address3[random.nextInt(4)]);
sb.append(random.nextInt(1000)+1);
sb.append("號");
return?sb.toString();
}
}
import?javax.swing.*;
import?javax.swing.event.TreeSelectionEvent;
import?javax.swing.event.TreeSelectionListener;
import?javax.swing.table.DefaultTableModel;
import?javax.swing.tree.DefaultMutableTreeNode;
import?java.awt.*;
import?java.util.*;
import?java.util.List;
public?class?StudentManage?extends?JFrame{
public?final?static?String[]?CH_NUM?=?{"一","二","三","四","五","六","七","八","九","十"};
public?final?static?String?ROOT?=?"班級管理";
public?final?static?int?GRADE_NUM?=?3;
public?final?static?int?CLASS_NUM?=?3;
private?MapString,?ListStudent?classes;
public?StudentManage()?{
setTitle("學生管理系統(tǒng)");
setSize(300,?300);
setLayout(new?BorderLayout());
if(classes?==?null)?classes?=?new?HashMap();
DefaultMutableTreeNode?top?=?new?DefaultMutableTreeNode(ROOT);
DefaultMutableTreeNode[]?gradeNodes?=?new?DefaultMutableTreeNode[GRADE_NUM];
for?(int?i?=?0;?i??GRADE_NUM;?i++)?{
gradeNodes[i]?=?new?DefaultMutableTreeNode(CH_NUM[i]?+?"年級");
for?(int?j?=?0;?j??CLASS_NUM;?j++)?{
gradeNodes[i].add(new?DefaultMutableTreeNode(CH_NUM[j]?+?"班"));
}
top.add(gradeNodes[i]);
}
final?JTree?tree?=?new?JTree(top);
String?title[]?=?{"ID","姓名","性別","年齡","地址"};
final?DefaultTableModel?model?=?new?DefaultTableModel(title,?0);
JTable?table=new?JTable(model);
tree.addTreeSelectionListener(new?TreeSelectionListener()?{
@Override
public?void?valueChanged(TreeSelectionEvent?e)?{
DefaultMutableTreeNode?node?=?(DefaultMutableTreeNode)?tree?.getLastSelectedPathComponent();
if?(node?==?null)?return;
Object?object?=?node.getUserObject();
if?(node.isLeaf())?{
ListStudent?stdList?=?classes.get(getFullPath(node));
Object[][]?data?=?new?Object[stdList.size()][5];
for?(int?i?=?0;?i??stdList.size();?i++)?{
data[i][0]?=?stdList.get(i).getId();
data[i][1]?=?stdList.get(i).getName();
data[i][2]?=?stdList.get(i).getSex();
data[i][3]?=?stdList.get(i).getAge();
data[i][4]?=?stdList.get(i).getAddress();
}
while(model.getRowCount()0){
model.removeRow(model.getRowCount()-1);
}
for?(int?i?=?0;?i??stdList.size();?i++)?{
model.addRow(data[i]);
}
model.fireTableDataChanged();
}
}
});
add(tree,?BorderLayout.WEST);
add(new?JScrollPane(table),?BorderLayout.CENTER);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private?String?getFullPath(DefaultMutableTreeNode?defaultMutableTreeNode){
StringBuilder?sb?=?new?StringBuilder();
Object[]?objs?=?defaultMutableTreeNode.getUserObjectPath();
for?(int?i?=?0;?i??objs.length;?i++)?{
sb.append(objs[i]);
}
return?sb.toString().replace(ROOT,"");
}
public?void?init(){
for?(int?i?=?0;?i??GRADE_NUM;?i++)?{
for?(int?j?=?0;?j??CLASS_NUM;?j++)?{
int?n?=?new?Random().nextInt(30)+1;
ListStudent?stdList?=?new?ArrayList(n);
for?(int?k?=?0;?k??n;?k++)?{
stdList.add(new?Student(RandomUtils.randomIntId(),RandomUtils.randomName(),RandomUtils.randomSex(),
RandomUtils.randomAge(6,12),RandomUtils.randomAddress()));
}
classes.put(CH_NUM[i]?+?"年級"+?CH_NUM[j]?+"班",?stdList);
}
}
}
public?static?void?main(String[]?args)?{
StudentManage?studentManage?=?new?StudentManage();
studentManage.init();
}
}
class?Student?{
private?int?id;
private?String?name;
private?String?sex;
private?int?age;
private?String?address;
public?Student(int?id,?String?name,?String?sex,?int?age,?String?address)?{
this.id?=?id;
this.name?=?name;
this.sex?=?sex;
this.age?=?age;
this.address?=?address;
}
public?Student()?{
}
public?int?getId()?{
return?id;
}
public?String?getName()?{
return?name;
}
public?String?getSex()?{
return?sex;
}
public?int?getAge()?{
return?age;
}
public?String?getAddress()?{
return?address;
}
@Override
public?String?toString()?{
return?"Student{"?+
"id="?+?id?+
",?name='"?+?name?+?'\''?+
",?sex='"?+?sex?+?'\''?+
",?age="?+?age?+
",?address='"?+?address?+?'\''?+
'}';
}
}
文章名稱:java答題系統(tǒng)設計代碼 java程序設計基礎題庫及答案
URL網址:http://chinadenli.net/article18/hihedp.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供手機網站建設、做網站、用戶體驗、網站制作、營銷型網站建設、微信公眾號
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)