輸出正常,但輸出是大寫字母,我希望輸出是小寫字符,我該怎么辦?
import java.util.Scanner;
public class Q2 {
public static void main(String[] args) {
int a[]=new int[26];
Scanner sc = new Scanner (System.in);
String str=sc.nextLine();
for(int i = 0; i<str.length();i ) {
if(str.charAt(i)>=65 && str.charAt(i)<=90) {
a[str.charAt(i)-65] ;
}
else if(str.charAt(i)>=97 && str.charAt(i)<=122) {
a[str.charAt(i)-97] ;
}
}
for(int i=0;i<26;i ) {
if(a[i]>0) {
System.out.print(" " (char )(i 65) "(" a[i] ")");
}
}
}
}
uj5u.com熱心網友回復:
'A'是 65。'a'是 97。在最終回圈中使用 97 而不是 65。
或者'a'直接使用而不是數字。這使您在該代碼中所做的事情更加明顯。
uj5u.com熱心網友回復:
看看這篇文章,有一個可接受的答案如何在 Java 中在大寫和小寫之間轉換字串?
你可能會做這樣的事情
import java.util.Scanner;
public class Q2 {
public static void main(String[] args) {
int a[]=new int[26];
Scanner sc = new Scanner (System.in);
String str=sc.nextLine();
String lowerCaseInput = str.toLowerCase();
System.out.print(lowerCaseInput);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324471.html
上一篇:根據T/F欄,只粘貼矢量的一部分
