我怎样才能使一些数字正确合理?我不明白。我对Java真的很陌生。:-/ 例如,每当我尝试使此代码正确合理时,它都会给我错误。这是我找到的一些示例代码:
import java.util.Scanner;
public class JFindAlphabete
{
static Scanner sc = new Scanner(System.in );
public static void main(String[] Theory)
{
JWaffles MyWaffles = new JWaffles();
MyWaffles.ProgramHeading();
System.out.println("Enter a string:" );
String SentenceContents = sc.nextLine( );
int SpaceCount = SentenceContents.length() - SentenceContents.replaceAll(" ", "").length( );
int VowelCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[aeiou]", "").length( );
int ConsonantCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)(?=[a-z])[^aeiou]", "").length( );
int SpecialCharCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[^a-z ]", "").length( );
int WordCount = SentenceContents.trim().split("\\s+").length;
System.out.println("There are " + VowelCount + " vowels in this sentance" );
System.out.println("There are " + ConsonantCount + " consonants in this sentance" );
System.out.println("There are " + SpaceCount + " spaces in this sentance" );
System.out.println("There are " + SpecialCharCount + " special characters in this sentance");
System.out.println("There are " + WordCount + " words in this sentance" );
}
}