「java中done」JAVA中的或
今天给各位分享java中done的知识,其中也会对JAVA中的或进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java中输入一串数字输再入done就终止输入的语句
- 2、java中先读取文本文档,然后对文档中的内容再对“|”后面的数字进行排序,再存入新的文本文档
- 3、java for( ;!done;)是什么意思 谢谢
- 4、JAVA if语句 请分析下列语句过程 为什么输出是“Done”
java中输入一串数字输再入done就终止输入的语句
先获取用户输入内容,再比较输入内容
把o改成done就可以了
java中先读取文本文档,然后对文档中的内容再对“|”后面的数字进行排序,再存入新的文本文档
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class SortStringDemo {
public static void main(String[] args) throws IOException {
//读取文本数据
File file = new File("1.txt");
ListString list = new ArrayList();
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String temp = scanner.nextLine();
if (!temp.equals("")) {
list.add(temp);
}
}
scanner.close();
// sub字符串,再使用Integer.comparTo() 如:1 2 11 这种数字大小排序
Collections.sort(list, new ComparatorString() {
@Override
public int compare(String o1, String o2) {
Integer n1 = Integer.valueOf(o1.substring(o1.indexOf("|") + 1, o1.length()));
Integer n2 = Integer.valueOf(o2.substring(o2.indexOf("|") + 1, o2.length()));
return n1.compareTo(n2);
}
});
System.out.println("按照数字大小排序:\t" + list);
// sub字符串,再使用String.comparTo() 如:1 11 2 这种按照字符串序号排序
Collections.sort(list, new ComparatorString() {
@Override
public int compare(String o1, String o2) {
String string1 = o1.substring(o1.indexOf("|") + 1, o1.length());
String string2 = o2.substring(o2.indexOf("|") + 1, o2.length());
return string1.compareTo(string2);
}
});
System.out.println("按照子串排序:\t" + list);
//存储文本数据
File file2 = new File("2.txt");
PrintWriter pw = new PrintWriter(file2);
for (int i = 0; i list.size(); i++) {
pw.println(list.get(i));
}
pw.close();
}
}
java for( ;!done;)是什么意思 谢谢
for循环语句的话,是可以省略掉第一和第三的语句的,但这样写,其实没有多大意义,语法上是支持的
JAVA if语句 请分析下列语句过程 为什么输出是“Done”
因为done=false 赋值,然后判断done值为true
所以输出了呗。
估计要使这样的话 输出应该就是
Not
Finished
boolean done=false;
if(done=true)
System.out.println("Not");
if(done=false)
System.out.println("Done");
else
System.out.println("Finished");
关于java中done和JAVA中的或的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-20,除非注明,否则均为
原创文章,转载请注明出处。