1
과 함께 null을 반환하는 else 문이 처음으로 질문을하는 경우 내 타이틀이 정확한지 확실하지 않아서 Java에 익숙하지 않기 때문에 ... 기본적으로 프로그램이 모두 null을 반환합니다. 이름에 공백이 없을 때 changeNameFormat 메서드에서 "네 이름에 공백이 없다"라는 문자를 출력하고 다음 메서드로 넘어 간다. 현재 내 코드는 다음과 같습니다. 논리적으로는 적어도 나에게는 의미가 있지만 전문가는 아닙니다.부울 연산자
import java.util.*;
public class Lab11 {
static String name, first, last, word;
static boolean space;
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
System.out.println("Input your name: ");
name = input.nextLine();
changeNameFormat();
if (space = true) {
System.out.println("Your name is : " + first + " " + last);
System.out.println("Your first name is : " + first);
System.out.println("Your last name is : " + last);
}
else {
System.out.println("Your name contains no spaces");
}
System.out.println("Input word for palindrome test: ");
word = input.nextLine();
if (palindrome(word)) {
System.out.println(word + " is a palindrome");
}
else {
System.out.println(word + " is NOT a palindrome");
}
}
public static void changeNameFormat() {
if (name.contains(" ")) {
String [] split = name.split(" ", 2);
first = split[0];
String last = split[1];
space = true;
}
else {
space = false;
}
}
public static boolean palindrome(String w) {
System.out.println("Checking if " + word + " is a palindrome.");
System.out.println("... Loading...");
String reverse = "";
for (int i = w.length() - 1 ; i >= 0 ; i--) {
reverse = reverse + w.charAt(i);
}
if (w.equalsIgnoreCase(reverse)) { // case insensitive check
return true;
}
else {
return false;
}
}
}
(공간)'대신'테스트 충분한 경우'== TRUE ';-) – alterfox
덕분에 많이 :) 수 내가 그걸 잡지 못했다고 생각하지 않아. – Vemigod