用 Python 或者 Java 实现
py2
print >> open('test','w'),raw_input().upper()
如果我是面试官,这样的答案不合格,没有任何异常处理,没有任何判断,这样的一个代码出自测试手里,
一定是个不合格的测试
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
FileWriter fw = new FileWriter(new File("test.txt"));
fw.write(str.toUpperCase());
fw.close();
s = input('请输入英文字符:')
while not s.isalpha():
s = input('请输入英文字符:')
with open('test.txt', 'w', encoding='utf-8') as f:
f.write(s.upper())
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
System.out.println(line);
FileWriter fw = null;
File file = new File("test.txt");
if (! file.exists()){
file.createNewFile();
}
fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(line.toUpperCase(),0,line.length());
bw.close();
Scanner scan=new Scanner(System.in);
String str=scan.next();
String Ustr=str.toUpperCase();
File f=new File("C:\Users\dsp\Desktop\test.txt");
if(! f.exists()) {
try {
f.createNewFile();
System.out.println("创建成功");
FileOutputStream sr=new FileOutputStream(f);
byte[] bytes = Ustr.getBytes();
sr.write(bytes);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
try {
FileOutputStream sr = new FileOutputStream(f);
byte[] bytes = Ustr.getBytes();
sr.write(bytes);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
根据 ASCII 码转换
strs = input('请输入字符:')
try:
new = strs.upper()
except Exception as e:
print(e)
else:
with open('test.txt','w',encoding='utf-8') as f:
f.write(new)