이 웹 사이트에서 조사한 내용에도 불구하고이 오류를 이해할 수 없습니다. 처음에는 프로그램이 실행되었지만 내게 "y"가이고, 유효성 검사기 선택은 "n", "n", "n"이 모두 포함되어있었습니다. 그래서, 내 프로그램에서 주위를 둘러 보았다. 그것을 발견하고 해결했다. 이제 나는이 actual and format arguments lists differ in length
문제에 직면 해있다. 다른 변수를 사용하여 변수 유형을 변경하는 등 다양한 작업을 시도했습니다."실제 및 형식 인수 목록의 길이가 다릅니다."
여기 내 코드가 있습니다.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package roshambo;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author Owner
*/
public class Roshambo {
private String name;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String choice = "y";
String player;
Scanner sc = new Scanner(System.in);
Random random = new Random();
char[] ch = new char[]{'r','p','s'};
int r = random.nextInt(ch.length);
char raCh = ch[r];
while (choice.equalsIgnoreCase("y")) {
System.out.println("Welcome to Roshambo!");
System.out.println("");
//System.out.print("Please enter your name here - ");
//String player = sc.nextLine();
String player1 = Validator.getRequiredString("Please enter your name here - ",player);
String roshambo = sc.nextLine();
String roshambo1 = Validator.getChoiceString1("Please choose Rock, Paper or Scissors. (R/P/S) - ",'r','p','s');
choice = getChoiceString("Play Again? (y/n): ","y","n");
System.out.println("");
}
}
public static String getChoiceString(String prompt, String str1, String str2)
{
boolean isValid = false;
Scanner sc = new Scanner(System.in);
String choice = "";
while (isValid == false) {
System.out.print(prompt);
choice = sc.next();
if (choice.equalsIgnoreCase(str1) || choice.equalsIgnoreCase(str2)) {
isValid = true;
}
sc.nextLine();
}
return choice;
}
}
내가 뭘 잘못하고 있니? 또한 두 Validator 코드 사이에 문제가 있다고 생각하므로 Validator 코드를 추가 할 것입니다.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package roshambo;
import java.util.Scanner;
/**
* @author Owner
*/
public class Validator {
// force the user to enter a string
public static String getRequiredString(String prompt) {
Scanner sc = new Scanner(System.in);
String input = "";
boolean isValid = false;
while (isValid == false) {
System.out.print(prompt);
input = sc.nextLine();
if (input.equals("")) {
System.out.println("Error! This entry is required. Try again.");
}
else {
isValid = true;
}
}
return input;
}
// force the user to enter one of three strings
public static String getChoiceString1(String prompt, String str1, String str2, String str3) {
String input = "";
boolean isValid = false;
while (isValid == false) {
input = getRequiredString(prompt);
if (input.equalsIgnoreCase(str1) || input.equalsIgnoreCase(str2) || input.equalsIgnoreCase(str3)) {
isValid = true;
}
else {
System.out.println("Error! Entry must be '"+ str1 +"', '"+ str2 +"', or '"+ str3 +"'. Try again.");
}
}
return input;
}
}
미리 도움을 청하십시오! Validator 클래스에서
내 파트의 Herpaderp. 고맙습니다. 다음 오류 시간! 앞으로! –