-1
나는 오류를 얻을 무효 필요 : 문자열 크레딧 카드를 java.lang.String의 = mainintro(); ^ Project1.java:14 : 결과 유형이 void 인 값을 반환 할 수 없습니다. return creditcard; ^ 이 오류 호환되지 않는 유형
import java.util.*; // so that I can use Scanner
public class Project1{
public static void main(String[] arg){
String creditcard=mainintro();
checksize(creditcard);
checkprefix(creditcard);
}
public static void mainintro(){//Displays the intro message
Scanner console = new Scanner(System.in);
System.out.println("Enter a credit card number from 13 to 16 digits long:");
String creditcard = console.next();
return creditcard;
}
public static void checksize(String size){
int stringsize=size.length();//The Length of the creditcard
if(stringsize>=17||stringsize<=12){//Checks the size
System.out.println("The Credit card must be 13 to 16 numbers.");
System.out.println("");
System.out.println(size);
mainintro();
}else{System.out.println(size);}
}
public static void checkprefix(String creditcard){
System.out.println(creditcard);
}
}
내가 = ""문자열 크레딧 카드를 정의하는 경우
; main에서는 작동하지만 ""변수 만 사용합니다. 이 문제를 어떻게 해결할 수 있습니까?
숙제 것 같은데, 그래서 아마 같은 태그되어야한다. "무효"유형의 의미를 찾았습니까? 이를 이해하면 void 함수에서 값을 반환하려고 할 때 오류가 발생하는 이유를 알 수 있습니다. – Marvo