BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuffer sb = new StringBuffer(); String line; while(null != (line = br.readLine())) { sb.append(line); if(true == line.endsWith("#")) { break; } } int flag = sb.charAt(0); for(int i = 1; i < sb.length() - 1; i ++) { if(flag > sb.charAt(i)) { flag = sb.charAt(i); } } System.out.print((char)flag);
我是这样觉得: BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = null; while ((str = br.readLine()) != null) { if (str.endWith("#")) { return; } } char[] ch = str.toCharArray(); Arrays.sort(ch); System.out.println(ch[0]);
public class Main { public static void main(String[] args) throws IOException { Reader reader = new BufferedReader(new InputStreamReader(System.in)); int c = reader.read(); int min = c; while ((c = reader.read()) != '#') { if (c < min) { min = c; } } System.out.println((char) min); } }
应该在用以下方式吧???因为System.in只能接收到enter的时候他才能认为此次输入结束了.没法能过一个"#"来判断.所以只能用如下方式.不知道对不对.import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays;public class Test3 { public static void main(String[] args) throws IOException { StringBuffer strb = new StringBuffer(); String str = ""; while (true) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); str = br.readLine(); if (str.endsWith("#")) { break; } strb.append(str); } char[] cha = strb.toString().toCharArray(); Arrays.sort(cha); for (int i = 0; i < cha.length; i++) { System.out.println(cha[i]); } } }
StringBuffer sb = new StringBuffer();
String line;
while(null != (line = br.readLine()))
{
sb.append(line);
if(true == line.endsWith("#"))
{
break;
}
}
int flag = sb.charAt(0);
for(int i = 1; i < sb.length() - 1; i ++)
{
if(flag > sb.charAt(i))
{
flag = sb.charAt(i);
}
}
System.out.print((char)flag);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while ((str = br.readLine()) != null) {
if (str.endWith("#")) {
return;
}
}
char[] ch = str.toCharArray();
Arrays.sort(ch);
System.out.println(ch[0]);
Reader reader = new BufferedReader(new InputStreamReader(System.in));
int c = reader.read();
int min = c;
while ((c = reader.read()) != '#') {
if (c < min) {
min = c;
}
}
System.out.println((char) min);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;public class Test3 {
public static void main(String[] args) throws IOException {
StringBuffer strb = new StringBuffer();
String str = "";
while (true) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
if (str.endsWith("#")) {
break;
}
strb.append(str);
}
char[] cha = strb.toString().toCharArray();
Arrays.sort(cha);
for (int i = 0; i < cha.length; i++) {
System.out.println(cha[i]);
}
}
}
然后再一一比较
保留最小的..再转换成char输出