import?java.util.ArrayList;
成都創(chuàng)新互聯(lián)公司-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比克拉瑪依網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式克拉瑪依網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋克拉瑪依地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴(lài)。
import?java.util.Collections;
import?java.util.Comparator;
import?java.util.List;
public?class?Sort?{
public?static?void?main(String[]?args)?{
Student?p1?=?new?Student(1001,?"小明",?20);
Student?p2?=?new?Student(1002,?"小紅",?21);
Student?p3?=?new?Student(1003,?"小黑",?19);
ListStudent?list?=?new?ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類(lèi)型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的學(xué)號(hào)進(jìn)行升序排列
if?(o1.getId()??o2.getId())?{
return?1;
}
if?(o1.getId()?==?o2.getId())?{
return?0;
}
return?-1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類(lèi)型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的年齡進(jìn)行升序排列
if?(o1.getAge()??o2.getAge())?{
return?1;
}
if?(o1.getAge()?==?o2.getAge())?{
return?0;
}
return?-1;
}
});
write(list);
}
public?static?void?write(ListStudent?list)?{
for?(Student?s?:?list)?{
System.out.println(s.getId()?+?"\t"?+?s.getName()?+?"\t"
+?s.getAge());
}
}
}
public?class?Student?{
private?int?id?;
private?String?name;
private?int?age;
//構(gòu)造方法
public?Student(int?id,String?name,int?age){
this.id?=?id;
this.name?=?name;
this.age?=?age;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getAge()?{
return?age;
}
public?void?setAge(int?age)?{
this.age?=?age;
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JButton;
public class Stmessege {
Font font = new Font("楷體", Font.BOLD, 18);
private Frame m = new Frame("登陸成功界面");
protected Window f;
public Stmessege() {
m.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
m.setVisible(false);
m.dispose();
System.exit(0);
}
});
m.setSize(460, 360);
m.setBackground(Color.green);
m.setLayout(null);
m.setLocationRelativeTo(null);
Label l0 = new Label("管理員信息");
Font font1 = new Font("楷體", Font.BOLD, 32);
l0.setForeground(Color.blue);
l0.setSize(180, 50);
l0.setLocation(150, 30);
l0.setFont(font1);
final Label l1 = new Label("姓名:");
l1.setSize(60, 20);
l1.setLocation(10, 100);
l1.setFont(font);
TextField tf1 = new TextField("黃朋");
tf1.setForeground(Color.blue);
tf1.setBackground(Color.white);
tf1.setSize(50, 20);
tf1.setLocation(70, 100);
final Label l2 = new Label("學(xué)號(hào):");
l2.setSize(60, 20);
l2.setLocation(140, 100);
l2.setFont(font);
TextField tf2 = new TextField("111265");
tf2.setForeground(Color.blue);
tf2.setBackground(Color.white);
tf2.setSize(60, 20);
tf2.setLocation(190, 100);
final Label l3 = new Label("性別:");
l3.setSize(60, 20);
l3.setLocation(280, 100);
l3.setFont(font);
TextField tf3 = new TextField("男");
tf3.setForeground(Color.blue);
tf3.setBackground(Color.white);
tf3.setSize(40, 20);
tf3.setLocation(360, 100);
final Label l4 = new Label("班級(jí):");
l4.setSize(60, 20);
l4.setLocation(10, 170);
l4.setFont(font);
TextField tf4 = new TextField("611231");
tf4.setForeground(Color.blue);
tf4.setBackground(Color.white);
tf4.setSize(60, 20);
tf4.setLocation(67, 170);
final Label l5 = new Label("系別:");
l5.setSize(60, 20);
l5.setLocation(140, 170);
l5.setFont(font);
TextField tf5 = new TextField("計(jì)算機(jī)工程系");
tf5.setForeground(Color.blue);
tf5.setBackground(Color.white);
tf5.setSize(80, 20);
tf5.setLocation(200, 170);
final Label l6 = new Label("成績(jī):");
l6.setSize(60, 20);
l6.setLocation(280, 170);
l6.setFont(font);
TextField tf6 = new TextField("95");
tf6.setForeground(Color.blue);
tf6.setBackground(Color.white);
tf6.setSize(40, 20);
tf6.setLocation(360, 170);
final Label l7 = new Label("專(zhuān)業(yè):");
l7.setSize(60, 20);
l7.setLocation(10, 230);
l7.setFont(font);
TextField tf7 = new TextField("軟件技術(shù)");
tf7.setForeground(Color.blue);
tf7.setBackground(Color.white);
tf7.setSize(60, 20);
tf7.setLocation(70, 230);
JButton btn1 = new JButton("添加");
btn1.setForeground(Color.blue);
btn1.setSize(80, 38);
btn1.setLocation(35, 300);
btn1.setFont(font);
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 插入();
m.setVisible(true);
}
});
JButton btn2 = new JButton("查詢(xún)學(xué)生學(xué)籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200, 38);
btn2.setLocation(135, 300);
btn2.setFont(font);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Stmessege1 f;
try {
f = new Stmessege1();
f.Stmessege11();
m.setVisible(true);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton btn3 = new JButton("刪除");
btn3.setForeground(Color.blue);
btn3.setSize(80, 38);
btn3.setLocation(350, 300);
btn3.setFont(font);
btn3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 刪除();
//f.setVisible(false);
m.setVisible(true);
}
});
JButton btn4 = new JButton("更新");
btn4.setForeground(Color.blue);
btn4.setSize(80, 38);
btn4.setLocation(200, 230);
btn4.setFont(font);
btn4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 更新();
m.setVisible(true);
}
});
m.add(l0);
m.add(l1);
m.add(tf1);
m.add(l2);
m.add(tf2);
m.add(l3);
m.add(tf3);
m.add(l4);
m.add(tf4);
m.add(l5);
m.add(tf5);
m.add(l6);
m.add(tf6);
m.add(l7);
m.add(tf7);
m.add(btn1);
m.add(btn2);
m.add(btn3);
m.add(btn4);
m.setVisible(true);
}
public static void main(String[] args) {
new Stmessege();
}
}
可以仿照我的做一下,希望采納,我才一級(jí)哦
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class TestString {
public static void main(String[] args) throws IOException {
boolean flag = false;
do {
System.out.println();
System.out.println("Do you want to continue?(Y/N)");
Scanner scan = new Scanner(System.in);
String banlance = scan.next();
if (banlance.equals("Y")) {
flag = true;
} else if(banlance.equals("N")) {
System.out.println("End!");
break;
} else {
System.out.println("Error Input!");
}
System.out.print("Please input the String: ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String str = br.readLine();
StringBuffer strBuffer = new StringBuffer(str);
for(int i=0; istrBuffer.length(); i++) {//將元音字母先刪掉
char c = strBuffer.charAt(i);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
}
}
for(int i=0,j=i+1; jstrBuffer.length(); i++,j++) {//處理重復(fù)輔音字母
char c1 = strBuffer.charAt(i), c2 = strBuffer.charAt(j);
if(c1 == c2) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
--j;
}
}
System.out.println(strBuffer);
} while (flag = true);
}
}
測(cè)試與結(jié)果: