public class test3{
public static void main(String []args) {
String FilePath="d:\\javaTest\\outputtxt";
writeAll(FilePath);
}
private static void writeAll(String filePath) {
File output = new File(filePath);
String outputStr = "";
Scanner sc = new Scanner(Systemin);
Systemoutprintln("请输入信息:");
while (true) {
String str = scnextLine();
if (str == null || ""equals(str)) {
Systemerrprintln("退出\n\n");
break;
}
outputStr += str + "\r\n";
}
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(output, true);
bw = new BufferedWriter(fw);
bwwrite(outputStr);
Systemoutprintln("您输入的信息(姓名,学号,成绩):\n" + outputStr + "\n已写入:" + filePath);
} catch (IOException e) {
eprintStackTrace();
} finally {
try {
bwflush();
fwflush();
bwclose();
fwclose();
} catch (IOException e) {
eprintStackTrace();
}
}
}
}
if(scnext()=="1")改为if("1"equalsIgnoreCase(scnext()))就可以了。改后的程序如下:
我运行了,现在就可以了。
楼主,字符串的比较相等,不要用“==”,而是用equalsIgnoreCase。字符串的“==”,表示指向同一个字符串对象。具体,你可以网上了解一下。
public void go(){
Systemoutprintln("请选择你要做的事情:添加/修改输入1,删除输入2");
Scanner sc=new Scanner(Systemin);
if(schasNext()){
if("1"equalsIgnoreCase(scnext())){
Systemoutprintln("你选择了1");
}
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner sc = new Scanner(Systemin);
Systemoutprintln("请输入歌词:");
String s = scnextLine();
String[] x = ssplit(" ");
for(int i = 0;i<xlength;i++){
Systemoutprintln(x[i]);
}
}
以上就是关于编写java程序实现以下功能:从键盘输入学生姓名、学号、成绩,并保存到文本文件中,重复进行直到遇到空格符全部的内容,包括:编写java程序实现以下功能:从键盘输入学生姓名、学号、成绩,并保存到文本文件中,重复进行直到遇到空格符、java获取键盘输入、在java中怎么从键盘输入一段歌词以空格用split()分割等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)