发布网友 发布时间:2022-04-24 14:27
共2个回答
热心网友 时间:2023-10-16 08:53
public class UpcaseFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String file1="//C:Test.txt";//源文件
String file2="//C:Test2.txt";//目标文件
FileWriter fw;
FileReader fr;
int temp = 0;
int count1=0;//统计小写
int count2=0;//统计大写
int count3=0;//统计其他字符
try {
fw=new FileWriter(file2);
fr=new FileReader(file1);
while ((temp = fr.read()) != -1) {
char ch = (char) temp;
if(ch>='a'&&ch<='z'){
count1++;
ch=(char) (ch-32);
}else if(ch>='A'&&ch<='Z'){
count2++;
}else{
count3++;
}
fw.write(ch);
fw.flush();
System.out.print(ch);
}
System.out.println("\n"+"小写字母有"+count1+"个");
System.out.println("大写字母有"+count2+"个");
System.out.println("其他字符有"+count3+"个");
fw.close();
fr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
LZ 代码在上 给积分吧
热心网友 时间:2023-10-16 08:53
public class Test{ public static void main(String[] args){ String s = "a" ; System.out.print(s) ; s=s.toUpperCase(); System.out.println("转换为大写字母为:"+s) ; } }