【济南中心】JavaEE基础班知识点整理
天地玄黄,宇宙洪荒。
如果你也和我一样看过不少网络小说,那你的想象力肯定很丰富,这点作为程序员是很重要的。
如果你和我一样喜欢《黑客帝国》《银河系漫游指南》《钢铁侠》《三体》《西部世界》。。。那有可能科幻就是你坚持钻研技术的动力来源。
虽然我们暂时不能像黑客帝国里一样进入虚拟世界,不能像邓肯一样到宇宙尽头餐馆吃饭,没有贾维斯的智能管家系统,也不能把机器人做的无法分辨真伪,但是如果没有人们对未来的想象我们的技术就没有了追求。
这些追求促使我们不断的学习,让技术不断的前进,我相信这些电影电视小说里的情节一定会实现。
抱有这样的期待和好奇很多同学来到黑马学习技术,首先接触的就是黑马的基础班。视频课程,讲义是必须的,但是我们还要有知识的梳理。今天我们就整理了基础班的一下问答和笔试题供大家交流学习。希望大家梳理一下自己的基础知识,基础知识是我们技术飞船的主架,主架坚固才能让我们在宇宙里航行的更远~
id | name | age | java | c | oc | chinese |
1 | zs | 12 | 100 | 98 | 100 | 20 |
2 | ls | 24 | 50 | 51 | 92 | 100 |
3 | andi | 34 | 20 | 10 | 15 | 60 |
4 | aliy | 21 | 30 | 100 | 15 | 65 |
5 | wn | 11 | 80 | 21 | 87 | 12 |
public class Garage {
private String name;
private String number;
private String colour;
private int price;
public Garage(String name, String number, String colour, int price) {
super();
this.name = name;
this.number = number;
this.colour = colour;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getColour() {
return colour;
}
@Override
public String toString() {
return "Garage [name=" + name + ", number=" + number + ", colour="
+ colour + ", price=" + price + "]";
}
public void setColour(String colour) {
this.colour = colour;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
public class Test01 {
public static void main(String[] args) throws IOException {
ArrayList<Garage> list = new ArrayList<>();
System.out.println("请输入自己喜欢的三种车的车名,车牌号,颜色,价格");
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
String name = sc.next();
String number = sc.next();
String colour = sc.next();
int price = sc.nextInt();
// System.out.println(name+" "+number+" "+colour+" "+price);
Garage cars = new Garage(name,number,colour,price);
list.add(cars);
System.out.println("添加成功!");
}
for (int j = 0; j < list.size() - 1; j++) { // 降序排列
for (int i = 0; i < list.size() - 1 - j; i++) {
Garage car1 = list.get(i);
Garage car2 = list.get(i + 1);
if (car1.getPrice() < car2.getPrice()) {
list.set(i + 1, car1);
list.set(i, car2);
}
}
}
BufferedWriter bf = new BufferedWriter(new FileWriter("a.txt"));
for (int i = 0; i < list.size(); i++) {
bf.append(list.get(i).toString());
bf.newLine();
bf.flush();
// System.out.println(list.get(i).toString());
}
bf.close();
System.out.println("信息已写入a.txt");
}
}
public class Test02 {
public static void main(String[] args) throws IOException {
System.out.println("请输入一个字符串");
Scanner sc = new Scanner(System.in);
String str = sc.next();
// System.out.println(str);
Set set = new HashSet();
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
set.add(chars);// 去重,
}
Map map = new HashMap();
for (int i = 0; i < chars.length; i++) {
if (set.contains(chars) && !map.containsKey(chars)) {
map.put(chars, 1);
} else if (set.contains(chars) && map.containsKey(chars)) {
map.put(chars, (int) map.get(chars) + 1);
}
}
BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"));
for (Object key : map.keySet()) {
bw.append(key + "出现了" + map.get(key) + "次");
bw.newLine();
bw.flush();
}
bw.close();
System.out.println("信息已写入a.txt");
}
}
public class Test03 {
public static void main(String[] args) {
System.out.println("请输入5个人的相关信息:姓名,年龄,性别");
ArrayList<Person> list = new ArrayList<>();
for (int i = 0; i < 3; i++) {
Scanner sc = new Scanner(System.in);
String name = sc.next();
int age = sc.nextInt();
String sex = sc.next();
Person p = new Person(name, age, sex);
list.add(p);
System.out.println("添加成功!");
}
for (int i = list.size()-1; i >=0; i--) {
if (list.get(i).getAge() > 60) {
System.out.println(list.get(i)+"已删除");
list.remove(i);
}
}
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i)+"---");
}
}
}
public class Test04 {
public static void main(String[] args) throws IOException {
Map<String,String> map = new HashMap<>();
System.out.println("请输入编号及内容");
for(int i=0;i<3;i++){
Scanner sc = new Scanner(System.in);
String str = sc.next();
String[] strs = str.split("=");
map.put(strs[0],strs[1]);
System.out.println("添加成功");
}
BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"));
for(String key : map.keySet()){
StringBuffer sb = new StringBuffer(map.get(key));
String value= sb.reverse().toString();
bw.append(key + "=" + value);
bw.newLine();
bw.flush();
}
System.out.println("信息已写入a.txt");
bw.close();
}
}
public class Test05 {
public static void main(String[] args) {
MyThread m1 = new MyThread();
Thread t1 = new Thread(m1, "003");
Thread t2 = new Thread(m1, "004");
t1.start();
t2.start();
}
}
class MyThread extends Thread {
private int i = 10;
public void run() {
while (i > 0) {
synchronized (this) {
System.out.println(Thread.currentThread().getName());
i--;
}
}
}
}
public class Test06 {
public static void main(String[] args) {
People p = new People();
Thread t1 = new Thread(p);
Thread t2 = new Thread(p);
Thread t3 = new Thread(p);
Thread t4 = new Thread(p);
Thread t5 = new Thread(p);
t1.setName("t1");
t2.setName("t2");
t3.setName("t3");
t4.setName("t4");
t5.setName("t5");
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
while (!p.flag);
for (Entry<String, Integer> entry : p.map.entrySet()) {
System.out.println(entry.getKey() + "抢了 " + entry.getValue() + "元");
}
}
}
class People extends Thread {
Map<String, Integer> map = new HashMap();
boolean flag = false;
private int num = 10;
public void run() {
while (true) {
synchronized (this) {
if (num > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
Random r = new Random();
int money = r.nextInt(7);
String name = Thread.currentThread().getName();
if (!map.containsKey(name)) {
map.put(name, money);
} else if (map.containsKey(name)) {
map.put(name, map.get(name) + money);
}
num--;
System.out.println(num + " " + name + " " + money);
} else {
flag = true;
break;
}
}
}
}
}
public class Test07 {
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/itheima";
String username = "root";
String password = "123";
Connection con = DriverManager.getConnection(url, username, password);
// 插入一条数据
Statement stat = con.createStatement();
// int row =
// stat.executeUpdate("INSERT INTO stu (sname,age,java,c,oc,chinese) VALUES('meng','26','80','8','100','20')");
// System.out.println(row);
// a筛选结果-输出年龄在20岁以上的学员所有学科的总分----------------------------------------------------
ResultSet rst = stat.executeQuery("SELECT*FROM stu WHERE age >20");
while (rst.next()) {
int sum = 0;
String name = rst.getString("sname");
sum = rst.getInt("java") + rst.getInt("c") + rst.getInt("oc")
+ rst.getInt("chinese");
System.out.println(name + "的总分是:" + sum);
}
rst.close();
// b修改数据-
// 将andi的java成绩改为100,C语言成绩改为60-------------------------------------------------
int a = stat
.executeUpdate("UPDATE stu SET java = 100,c = 60 WHERE sname = 'andi'");
// c.
// 在控制台上打印出Java学科和c学科都是60分以下的学员姓名-----------------------------------------------
ResultSet rst2 = stat
.executeQuery("SELECT sname FROM stu WHERE java <60 AND c < 60");
while (rst2.next()) {
System.out.println("Java学科和c学科都是60分以下的学员姓名 "
+ rst2.getString("sname"));
}
rst2.close();
// // d.
// 输出java,c,oc,chinese这四科的平均分-------------------------------------------------
// ResultSet rst3 = stat
// .executeQuery("SELECT AVG(java),AVG(c),AVG(oc),AVG(chinese) FROM stu");
// while (rst3.next()) {
// System.out.println("java平均分:" + rst3.getInt(1) + "\nc平均分:"
// + rst3.getInt(2) + "\noc平均分:" + rst3.getInt(3)
// + "\nchinese平均分:" + rst3.getInt(4));
// }
// rst3.close();
stat.close();
con.close();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |