日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java手动输入函数_Java程序如何添加一个函数,如果玩家输入错误,它将返回代码。...

發布時間:2025/4/5 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java手动输入函数_Java程序如何添加一个函数,如果玩家输入错误,它将返回代码。... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我的程序有問題,不是代碼問題,而是我要怎么做,這是我一直困惑的部分。只是為了讓你知道我是一個基本的Java編碼器,我不理解復雜的東西,所以請記住,我的代碼不是最好的。

——————————————————————————————————————————————程序說明---

在我向您展示我的問題之前,讓我們先來解釋一下它是如何工作的,好吧,當您執行程序時,它會提示您一個類似于視頻游戲中的菜單,但它是基于文本的,它會向您顯示不同的選項,如輸入玩家詳細信息、玩數學游戲顯示分數,然后退出。輸入玩家詳細信息它告訴玩家1輸入他/她姓名,然后告訴另一個輸入他/她玩家姓名,然后提示您返回菜單。玩數學游戲是要求玩家1輸入他/她數學公式,然后玩家2必須解決它,如果他得到正確的他/她得到10分,如果沒有,玩家沒有得到任何點。然后重復讓另一個玩家輸入他/她數學公式,然后提示您返回菜單。顯示分數-顯示誰在數學游戲中得到的分數最多-計算誰得到的分數最多如果他們兩個得到的分數相同,則表示平局,然后提示您返回菜單。最后一件事,退出選項,當你選擇該選項,它停止程序。如果玩家選擇了一個錯誤的選項,他會收到一條錯誤信息,并將您放回菜單

好的,這里是第一個類,叫做menu,另一個類,它與名為game parties的菜單相連接

所以這段代碼我自己找不到

import java.util.*;

public class Gamefunctions // this is a core when player choosess one of these options from the menu

{

String[] player =new String[2];

double scorea = 0; // verribles of all the objects

double scoreb = 0;

int i;

Scanner input = new Scanner(System.in);

double answer = 0;

double numA, numB;

char operator;

char operator2;

boolean quit = false;

double sum1;

double sum2;

public void enterDetails(){ // if player select enter details

for ( i=0;i<2;i++) {// tell's player to input he/she's name and stores them

int c=i;

System.out.println("Welcome to the maths quiz game please input player name "+c++);

player[i] = input.next();

}

}

public void mathGame(){ // if player select enter details

System.out.println("Please enter your equation please "+player[0]+" press enter for each number and mathematical symbol"); // tells the player 1 to input

System.out.println("");

System.out.println("such as for ex input a number or how many you like, then hit enter and input such as /*-+^ hit enter, then input any number one or how many you like ");

String s=input.next();

numA = Double.parseDouble(s); // numa and numb and operator is the aera of player to input he/she equation

operator = input.next().charAt(0);

numB = input.nextDouble();

if () {

if (operator == '+') {// this is if operator is one of these like +-*/^ and then it works out the sum

answer = numA + numB;

}

if (operator == '-') {

answer = numA - numB;

}

if (operator == '*') {

answer = numA * numB;

}

if (operator == '/') {

answer = numA / numB;

}

if (operator == '^') {

answer = Math.pow(numA, numB);

}

} else {

System.out.println("error input like for an example '10' enter '+' enter '10'");

}

System.out.println("");

System.out.println(player[1]+"\t solve the equation"); // tells other player to slove the equation

sum2 = input.nextDouble();

if (sum2 == answer){// checks if the answer from the player is good or not if its good he/she gets 10 points if he/she gets it wrong gets no points and shows the right answer so the player learns from his/she mistakes

scoreb = scoreb + 10.00;

System.out.println("correct you got 10 points to your score");

System.out.println("");

} else{

System.out.println("incorrect you got no points the correct answer was:"+"" + answer);

}

你知道當程序要求玩家輸入他的數學方程并輸出它,然后繼續程序并等待用戶輸入

public void mathGame(){ // if player select enter details

System.out.println("Please enter your equation please "+player[0]+" press enter for each number and mathematical symbol"); // tells the player 1 to input

System.out.println("");

System.out.println("such as for ex input a number or how many you like, then hit enter and input such as /*-+^ hit enter, then input any number one or how many you like ");

String s=input.next();

numA = Double.parseDouble(s); // numa and numb and operator is the aera of player to input he/she equation

operator = input.next().charAt(0);

numB = input.nextDouble();

假設玩家輸入的是10+10回車,但由于它們存儲在一個int的numa中,所以不能工作,我想發一條錯誤消息說你不能輸入10+10,你必須輸入10+10回車,這樣它才能工作

如果播放機輸入正確,它將繼續程序

所以,如果你解釋我的文章有任何問題,請允許我編輯它,謝謝你的時間:

總結

以上是生活随笔為你收集整理的java手动输入函数_Java程序如何添加一个函数,如果玩家输入错误,它将返回代码。...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。