我怎樣才能讓一些數字合理?我不明白。我對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" );
}
}
它「給你錯誤」?也許描述這些錯誤的性質會有所幫助;)另外,你應該能夠正確地使用printf/format。 – 2012-07-09 00:32:22
@fvu意思printf,手機自動更正。 – 2012-07-09 00:36:23