java課程設計算術運算測試
A. java編寫算術運算測試
真是沒啥好說的
B. java課程程序設計報告 課題:小學算術運算測試程序
這個你可找一個
簡單計算器
就可以,能實現你的要求
C. JAVA學年課程設計題目:四則運算測試(求高人解答啊~~)
首先要明白Vector和ArrayList在使用上非常相似,都可用來表示一組數量可變的對象應用的集合,並且可以隨機內地訪問其中的容元素。
Vector的方法都是同步的(Synchronized),是線程安全的(thread-safe),而ArrayList的方法不是,由於線程的同步必然要影響性能,因此,ArrayList的性能比Vector好。
當Vector或ArrayList中的元素超過它的初始大小時,Vector會將它的容量翻倍,而ArrayList只增加50%的大小,這樣,ArrayList就有利於節約內存空間。
所以這里用arraylist吧
應該是用來存儲每道題的答案用,比如:
第一道題
int num1 = 1;
int num2 = 2;
int num3 = num1 + num2;
List nums = new ArrayList();
nums.add(num3); //將計算結果存入數組中
System.out.println(nums.get(0)); //取值
這只是思路,你借鑒下吧
D. JAVA 算術運算測試
importjava.util.Random;
importjava.util.Scanner;
publicclassTestRandom{
publicstaticvoidmain(String[]args){
Randomrand=newRandom();
Scannerinput=newScanner(System.in);
while(true){
inta=rand.nextInt(100);
intb=rand.nextInt(100);
intresult=a+b;
System.out.println(a+"+"+b+"=?");
intyourGuess=input.nextInt();
if(yourGuess==result){
System.out.println("youareright");
}else{
System.out.println("youarewrong");
}
}
}
}
E. JAVA課設小學算數運算測試程序報告中界面設計部分的詳細設計與關鍵問
package demo;
import java.util.Scanner;
public class Test {
static Scanner sc = new Scanner(System.in);
public static boolean isNum(String str) {
boolean a = str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
boolean b = str.matches("^[-+]?$");
return a && !b;
}
public static double input(int i) {
System.out.print("輸入第" + i + "個數:");
String num = "";
do {
num = sc.next();
if (!isNum(num)) {
System.out.print("輸入的不為數字,請重新輸入:");
}
} while (!isNum(num));
return Double.parseDouble(num);
}
public static String input2() {
String operator = "";
boolean re;
System.out.print("輸入運算符(+、-、*、/、^):");
do {
operator = sc.next();
re = operator.equals("+") || operator.equals("-") || operator.equals("*") || operator.equals("/")
|| operator.equals("^");
if (!re) {
System.out.print("請輸入(+、-、*、/、^)中的一個:");
}
} while (!re);
return operator;
}
public static void main(String[] args) {
String judge = "";
do {
double n1 = input(1);
double n2 = input(2);
String result = "";
double res = 0;
String op = null;
op = input2();
switch (op) {
case "+":
res = n1 + n2;
break;
case "-":
res = n1 - n2;
break;
case "*":
res = n1 * n2;
break;
case "/":
if (n2 == 0) {
result = "除數不能為0";
} else {
res = n1 / n2;
}
break;
case "^":
res = Math.pow(n1, n2);
break;
}
if (result.isEmpty()) {
result = String.valueOf(res);
}
System.out.println("計算結果:" + n1 + op + n2 + "=" + result);
System.out.print("是否繼續?(Y/任意退出)");
judge = sc.next();
} while (judge.equals("Y") || judge.equals("y"));
System.out.println("謝謝使用_(:зゝ∠)_");
}
}
F. 誰有java算術運算測試代碼 100分
我有計算器的JAVA代碼。。。
G. java課程設計「小學算術運算測試程序」
花了好幾個小時,測試通過,希望樓主多給點分
import java.util.Scanner;
class Question{
private int firstParam;
private int secondParam;
private String operator;
private int answer;
private int score;
public int getFirstParam() {
return firstParam;
}
public void setFirstParam(int firstParam) {
this.firstParam = firstParam;
}
public int getSecondParam() {
return secondParam;
}
public void setSecondParam(int secondParam) {
this.secondParam = secondParam;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public int getAnswer() {
return answer;
}
public void setAnswer(int answer) {
this.answer = answer;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
//構造
public Question(int firstParam, int secondParam) {
this.firstParam = firstParam;
this.secondParam = secondParam;
}
}
public class StudentStudy {
private int questionNumber;
private String operator;
private Question[] questions;
private int rightNumber=0;
private int wrongNumber=0;
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public int getQuestionNumber() {
return questionNumber;
}
public void setQuestionNumber(int questionNumber) {
this.questionNumber = questionNumber;
}
public int getRightNumber() {
return rightNumber;
}
public void setRightNumber(int rightNumber) {
this.rightNumber = rightNumber;
}
public int getWrongNumber() {
return wrongNumber;
}
public void setWrongNumber(int wrongNumber) {
this.wrongNumber = wrongNumber;
}
public Question[] getQuestions() {
return questions;
}
public void setQuestions(Question[] questions) {
this.questions = questions;
}
public int getRandom(){
return (int)(Math.random()*10);
}
public int calculateByOperator(String operator,int first,int second){
switch(operator.charAt(0)){
case '+':
return first+second;
case '-':
return first-second;
default:
return 0;
}
}
public void makeQuestion(){
mywhile:
while(questions[questionNumber-1]==null){
Question question=new Question(getRandom(),getRandom());
for(int i=0;questions[i]!=null&&i<questionNumber;i++){
if((question.getFirstParam()==questions[i].getFirstParam())&&(question.getSecondParam()==questions[i].getSecondParam())){
continue mywhile;
}
}
for(int i=0;i<questionNumber;i++){
if(questions[i]==null){
questions[i]=question;
questions[i].setOperator(operator);
questions[i].setScore(100/questionNumber);
questions[i].setAnswer(calculateByOperator(operator,questions[i].getFirstParam(),questions[i].getSecondParam()));
break;
}
}
}
}
public StudentStudy(int questionNumber){
this.questionNumber=questionNumber;
questions=new Question[this.questionNumber];
}
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("現在開始測試,請填寫要測試的試題數量(1-100):");
int number=input.nextInt();
StudentStudy ss=new StudentStudy(number);
System.out.println("請選擇要測試的試題類型:1加法2減法");
int type=input.nextInt();
switch(type){
case 1:
ss.setOperator("+");
break;
case 2:
ss.setOperator("-");
break;
default:
System.out.println("輸入有誤,退出系統!");
System.exit(0);
}
ss.makeQuestion();
for(int i=0;i<number;i++){
System.out.println("第"+(i+1)+"題:"+ss.getQuestions()[i].getFirstParam()+ss.getQuestions()[i].getOperator()+ss.getQuestions()[i].getSecondParam()+"=?");
int answer=input.nextInt();
if(ss.getQuestions()[i].getAnswer()==answer){
ss.setRightNumber(ss.getRightNumber()+1);
System.out.println("回答正確!");
}
else{
ss.setWrongNumber(ss.getWrongNumber()+1);
System.out.println("回答錯誤!");
}
}
System.out.println("您總共答了"+ss.getQuestionNumber()+"道題,答對"+ss.getRightNumber()+"道,答錯"+ss.getWrongNumber()+"道,最後總分為:"+ss.getRightNumber()*100/ss.getQuestionNumber()+"分");
}
}
H. 用java編寫程序 課題:算術運算測試
你好,按照你的要求代碼如下,可以直接運行
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static void main(String[] args) {
int count = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
int c = (int) (Math.random() * 2);
int r = 0;
switch (c) {
case 0:
if (a + b >= 100) {
a = 100 - b;
}
System.out.print(a + " + " + b + " = ");
r = a + b;
break;
case 1:
if (a < b) {
int t = a;
a = b;
b = t;
}
System.out.print(a + " - " + b + " = ");
r = a - b;
}
int input;
try {
input = Integer.valueOf(in.readLine());
} catch (Exception e1) {
System.out.println("答案錯誤\n");
continue;
}
if (input == r) {
count++;
System.out.println("答案正確\n");
} else {
System.out.println("答案錯誤\n");
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("答對數量:" + count + "\n得分: " + count * 10);
}
}
I. Java課程設計小學生算數測試程序APPLET版
明白演算法就不難實現了。首先生成考題:十以內的兩個數字隨機組合,小學是沒有負數的,0不能做除數等細節考慮到,生成後。學生輸入答案,判斷是否和執行結果一致就行了。applet只是java的一種呈現方式,核心演算法都一樣。如果還不清楚,可以到碼源網聯系客服定製開發 源碼交易平台
J. 用Java設計一個小學算術運算測試軟體
package com.amixuse.calcdemo;
import java.util.ArrayList;
import java.util.Random;
public class Calc {
public static void main(String[] args) {
computeString = new ComputeString();
for (int i = 0; i < 100; i++) {
System.out.print(computeString.getComputeString()
+ computeString.getComputeResult() + "\t");
if ((i + 11) % 10 == 0) {
System.out.println();
}
}
computeString.setMaxNumber(100);
for (int i = 0; i < 100; i++) {
System.out.print(computeString.getComputeString()
+ computeString.getComputeResult() + "\t");
if ((i + 11) % 10 == 0) {
System.out.println();
}
}
}
}
class ComputeString {
private char flag = '+';
private int maxNumber = 10;
private int num1 = 0;
private int num2 = 0;
public static Random random = new Random(System.currentTimeMillis());
private char[] flags = new char[] { '+', '-', '*', '/' };
public int getMaxNumber() {
return maxNumber;
}
public void setMaxNumber(int maxNumber) {
this.maxNumber = Math.abs(maxNumber);
}
public char getFlag() {
return flag;
}
public void setFlag(char flag) {
this.flag = flag;
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = Math.abs(num1);
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = Math.abs(num2);
}
/**
* 根據指定的運算符號生成指定的算術表達式
* */
public String getComputeString(char flag) {
setFlag(flag);
setNum1(Math.abs(random.nextInt(maxNumber)));
StringBuffer result = new StringBuffer();
result.append(num1).append(flag);
switch (flag) {
case '+':
if (getNum1() == maxNumber - 1) {
setNum2(0);
} else {
setNum2(random.nextInt(maxNumber - num1 - 1));
}
break;
case '-':
if (getNum1() == 0) {
setNum2(0);
} else {
setNum2(random.nextInt(getNum1()));
}
break;
case '*':
if (getNum1() == 0) {
setNum2(random.nextInt(maxNumber));
} else {
setNum2(maxNumber / getNum1());
}
break;
case '/':
int tmp = Integer.MAX_VALUE;
if (getNum1() == 0) {
while (true) {
tmp = Math.abs(maxNumber);
if (tmp != 0) {
setNum1(tmp);
break;
}
}
result.setLength(0);
result.append(num1).append(flag);
}
setNum2(getGongyuesu(getNum1()));
break;
}
result.append(num2).append("=");
return result.toString();
}
/**
* 隨機生成運算符表達式
* */
public String getComputeString() {
setFlag(flags[random.nextInt(flags.length - 1)]);
return getComputeString(getFlag());
}
/**
* 產生最大公約數
*/
private int getGongyuesu(int number) {
ArrayList<Integer> result = new ArrayList<>();
int length = (int) Math.sqrt(number);
for (int i = 1; i <= length; i++) {
if (number % i == 0) {
result.add(new Integer(i));
}
}
int position = Math.abs(result.size());
position = position == result.size() ? position - 1 : position;
position = position <= 0 ? 0 : position;
return result.get(position);
}
/**
* 取得運算符結果
* */
public int getComputeResult() {
switch (flag) {
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
case '/':
return num1 / num2;
default:
return 0;
}
}
}
圖形界面暫時沒有弄。