我想比較string_1到string_2,看看它是否相等,而我試圖使一個單獨的字符串被完全大寫或under-套管。java8錯誤找不到符號當我使用comparetoIgnoreCase和Upper/UnderCase
import java.util.Scanner;
public class StringMethods
{
public static void main (String [] args)
{
Scanner s=new Scanner (System.in);
String string_1= s.next();
String string_2= s.next();
System.out.println ("a) Determine the length of string_1: " +string_1.length()+ "/t b) Determine the length of string_2: " +string_2.length()+"/tc) Concatenate both strings: " +string_1.concat(string_2)+"/td) Check if the two strings have same set of characters with regard to case: ");
if (string_1.equaltoIgnoreCase(string_2))
{
System.out.print ("equal.");
}
if ((string_1.comparetoIgnoreCase(string_2)>0)||(string_1.comparetoIgnoreCase(string_2)<0))
{
System.out.print ("They are not equal.");
}
System.out.println ("e) Convert string_1 to upper case: " +string_1.toUpperCase()+"/tf) Convert string_2 to lower case: " +string_2.toUnderCase()+"/tg) Extract a valid sub-string of multiple characters from string_1: " +string_1.substring(0,string_1.length));
}}
他們是完全一致的〜>'compareToIgnoreCase'和'equalsIgnoreCase' – nullpointer
'equaltoIgnoreCase'應該是'equalsIgnoreCase'。 ---'comparetoIgnoreCase'應該是'compareToIgnoreCase'。 ---'toUnderCase'應該是'toLowerCase'。 ---'length'應該是'length()'。 --- **使用IDE **來幫助這樣愚蠢的事情。或**閱讀文檔**,即['String']的javadoc(https://docs.oracle.com/javase/8/docs/api/java/lang/String.html)。 – Andreas