public test_03(){
init();
}
public void init(){
JLabel jl_1=new JLabel("用户名");
JLabel jl_2=new JLabel("密码");
JTextField jtf=new JTextField();
JPasswordField jpf=new JPasswordField();
JButton button_1=new JButton("确定");
JPanel panel=new JPanel();
panel.setLayout(null);
jl_1.setBounds(30, 50, 50, 30);
jl_2.setBounds(30,90,50,30);
jtf.setBounds(100, 50, 100, 30);
jpf.setBounds(100, 90, 100, 30);
button_1.setBounds(110, 130, 80, 30);
panel.add(jl_1);
panel.add(jl_2);
panel.add(jtf);
panel.add(jpf);
panel.add(button_1);
this.add(panel);
this.setSize(300, 250);
this.setLocation(400, 300);
this.setVisible(true);
}
public static void main(String[] args) {
new test_03();
}
package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class StringSort {
public static void main(String[] args) {
Listlist = new ArrayList ();
Scanner scanner = new Scanner(System.in);
String temp = scanner.nextLine();
while (!temp.equals("end")) {
list.add(temp);
temp = scanner.nextLine();
}
Collections.sort(list); // 按字典序正序排序
Collections.reverse(list); // 再将列表翻转
for (String str : list) {
System.out.println(str);
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class project {
public static void main(String[] args){
ArrayListas=new ArrayList ();
String s="";
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while((s=br.readLine())!=null&&!s.equals("end")){
as.add(s);
}
}catch(Exception e){
System.out.println("创建流失败!");
}
int size=as.size();
String[] data=new String[size];
for(int i=0;idata[i]=as.get(i);
}
for(int i=0;idata[i]=max(data,i);
System.out.println(data[i]);
}
}
public static String max(String[] data,int n){
String max=data[n];
for(int i=n;iif(max.compareTo(data[i])<0){
String temp=max;
max=data[i];
data[i]=temp;
}
}
return max;
}
}
那个我测试了下 a,b,c,d,e,f,g是对的。。其他没来得及测试。。。我不大会用ArrayList读取修改数据。。所以后面又耗费功夫改成了数组。。。。性能方面不行应该。一个暑假没写基本都忘了唉。。希望能帮上你
把得到的s.nextLine()放到一个ArrayList里,因为ArrayList里的东东都是有序的,所以倒过来输出就ok了
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String inputStr =in.nextLine();
String outStr= "";
while(!inputStr.equals("end")){
outStr += inputStr;
System.out.println("请再输入:");
inputStr = in.nextLine();
}
System.out.println("您输入的是:"+outStr);
}