これは説明するのが難しいかもしれませんが、私のクラスでこの問題を抱える唯一の傾向にあるので、基本的にはJava今プログラミング。私は基本的に変数の値をスキャンしてその変数をwhileループに持っていなければならない問題があります。プログラムを起動するとwhileループを開始しないという問題があります。それは私が数字を入力し続けることができますが、それは問題です、それは数字をスキャンし続けますが、それは一度だけスキャンする必要があり、ループに入りません。 これは、プログラムJavaプログラミングでは、プログラムはスキャナをwhileループに渡すことはありません
import java.util.Scanner;
public class Week05_NelsonPimentel_Assignment {
public static void main(String args[]){
int veraq;
int times = 0;
Scanner input = new Scanner(System.in);
System.out.println("Please enter how many coins you have");
veraq = input.nextInt();
while(veraq>0){
firstmachine(veraq);
howmanytimesplayed(times);
secondmachine(veraq);
howmanytimesplayed(times);
thirdmachine(veraq);
howmanytimesplayed(times);
}
System.out.println("You were able to play this many times before running out of quarters: " +times);
}
static int howmanytimesplayed(int times)
{
times++;
return times;
}
static int firstmachine(int veraq)
{
int times = 0;
if(times == 33){
veraq = veraq + 24;
times = 0;
System.out.println("Congradulations! On machine number one you have won $6.25!! You have this many coins left: " +veraq);
return veraq;
}
else if(times != 33)
{
veraq = veraq - 1;
times++;
return veraq;
}
return 0;
}
static int secondmachine(int veraq)
{
int times = 0;
if(times == 99){
veraq = veraq + 74;
times = 0;
System.out.println("Congradulations! On machine number two you have won $18.75!! You have this many coins left: " +veraq);
return veraq;
}
else if(times != 99)
{
veraq = veraq - 1;
times++;
return veraq;
}
return 0;
}
static int thirdmachine(int veraq)
{
int times = 0;
if(times == 9){
veraq = veraq + 6;
times = 0;**enter code here**
System.out.println("Congradulations! On machine number three you have won $1.75!! You have this many coins left: " +veraq);
return veraq;
}
else if(times != 9)
{
veraq = veraq - 1;
times++;
return veraq;
}
return 0;
}
}
0より大きい数字を入力すると、無限ループになります。 –
現在表示されているテキスト出力(印刷メッセージ)は何ですか? –
値で呼び出される内容と参照で呼び出される内容を理解する必要があります。次に、これらの概念がJavaのメソッドに引数を渡すことにどのように関係しているかを学ぶべきです – opensam