1
public static char getChoice(char choice) {
System.out.println("\nTake or stop? (t/s): ");
choice = sc.next()
.charAt(0);
if (choice == 't') {
System.out.print("Player Took");
choice = 't';
} else if (choice == 's') {
System.out.println("Player didnt take");
choice = 's';
}
return choice;
//return answer;
}
Это часть в основном Thats назвав егоМетод не возвращает правильное значение (Java)
//Checking if players score is 21 when the game begins
if(ptotal == 21)
{
System.out.print("\nPlayer wins!");
}
//Checking if the computers score is 21 when the game
else if(ctotal == 21)
{
System.out.print("\nComputer wins!");
}
//Checking if both scores are 21 which would be a tie
else if(ctotal == 21 && ptotal == 21)
{
System.out.print("\nTie!");
}
//If none above is true it will proceed to the loop
else
{
//getChoice(answer);
while(ptotal < 21 && answer == 't')//Loop conditions
{
getChoice(answer);
//Prompting user if they would like to take or stop
/*System.out.println();
System.out.print("Take or stop? (t/s): ");
answer = sc.next().charAt(0);
System.out.println("");*/
//Checking if the input is 't'
if(answer == 't')
{
//If true another card will be generated and added to the total value
System.out.print("\nPlayer draws: ");
pCard = getCard();
showCard(pCard);
ptotal += cardValue(pCard);
}
//Checking if input is 's'
else if(answer == 's')
{
System.out.println("Player Stops");
}
}
это должно спросить пользователя для ввода полукокса, а затем возвращают конкретный символ в зависимости от оператора if, но каждый раз, когда он возвращает его, когда я вызываю его из основного, он не будет отображать эти строки, но он не будет выбирать правильный символ. PLS помощи.
Если 'choice'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'зачем вам нужно переназначить его на одно и то же? В этой ситуации также нецелесообразно проходить в шар. – Li357
что я должен делать, потому что все, что я хочу сделать, это получить вход, а затем, когда вызывается в основном использовании, которое соответствует соответственно – Noobgrammer
. Я не вижу никаких проблем с кодом здесь. разместите код, вызывающий метод getChoice() ' –