(用JAVA)从键盘上读入一行字符,将其中大写字符转化成小写字符然后写到d:\test.txt中
2013-11-07
展开全部
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;public class Andian {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入字符串:");
String str = sc.next();
String s = str.toLowerCase();
File file = new File("d:\\test.txt");
try {
if(!file.exists())
file.createNewFile();
FileWriter fw = new FileWriter(file);
PrintWriter fo = new PrintWriter(fw);
fo.write(s);
fw.close();
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;public class Andian {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入字符串:");
String str = sc.next();
String s = str.toLowerCase();
File file = new File("d:\\test.txt");
try {
if(!file.exists())
file.createNewFile();
FileWriter fw = new FileWriter(file);
PrintWriter fo = new PrintWriter(fw);
fo.write(s);
fw.close();
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2013-11-07
展开全部
import java.util.Scanner;
import java.io.*;public class ReadChar{
public static void main(String args[])throws IOException{
Scanner sc = new Scanner(System.in);
System.out.println("请输入一行字符:");
String chars = sc.nextLine();
PrintStream ps = new PrintStream(new File("D:\\test.txt"));
for(int i=0;i<chars.length();i++){
char c = chars.charAt(i);
if(c<='Z' && c>='A'){
ps.print(c);
}
}
ps.close();
}
}
import java.io.*;public class ReadChar{
public static void main(String args[])throws IOException{
Scanner sc = new Scanner(System.in);
System.out.println("请输入一行字符:");
String chars = sc.nextLine();
PrintStream ps = new PrintStream(new File("D:\\test.txt"));
for(int i=0;i<chars.length();i++){
char c = chars.charAt(i);
if(c<='Z' && c>='A'){
ps.print(c);
}
}
ps.close();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询