From 91fe49bb30d73664c6d904f2e1366b7d5b087b78 Mon Sep 17 00:00:00 2001 From: xiao-a-qi <1307421235@qq.com> Date: Fri, 16 Apr 2021 07:37:56 +0800 Subject: [PATCH] first commit --- .../SQLQuery2.sql" | 462 ++++++++++++++++++ .../SQLQuery3.sql" | 41 ++ .../SQLQuery4.sql" | 53 ++ .../SQLQuery5.sql" | 39 ++ .../demo1.java" | 35 ++ .../demo2.java" | 16 + .../demo3.java" | 40 ++ .../demo4.java" | 18 + 8 files changed, 704 insertions(+) create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery2.sql" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery3.sql" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery4.sql" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery5.sql" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo1.java" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo2.java" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo3.java" create mode 100644 "\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo4.java" diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery2.sql" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery2.sql" new file mode 100644 index 0000000..fd81d59 --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery2.sql" @@ -0,0 +1,462 @@ +create database ClassicDb + +GO + + + +use ClassicDb + +GO + + + +create table StudentInfo + +( + + Id int PRIMARY key not null IDENTITY, + + StudentCode nvarchar(80), + + StudentName nvarchar(80), + + Birthday date not null, + + Sex nvarchar(2), + + ClassId int not null + +) + + + +GO + + + +-- select * from StudentInfo + + + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('01' , '赵雷' , '1990-01-01' , 'm',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('02' , '钱电' , '1990-12-21' , 'm',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('03' , '孙风' , '1990-12-20' , 'm',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('04' , '李云' , '1990-12-06' , 'm',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('05' , '周梅' , '1991-12-01' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('06' , '吴兰' , '1992-01-01' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('07' , '郑竹' , '1989-01-01' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('09' , '张三' , '2017-12-20' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('10' , '李四' , '2017-12-25' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('11' , '李四' , '2012-06-06' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('12' , '赵六' , '2013-06-13' , 'f',1) + +insert into StudentInfo (StudentCode,StudentName,Birthday,Sex,ClassId) values('13' , '孙七' , '2014-06-01' , 'f',1) + + + + + +GO + + + + + +CREATE TABLE Teachers + +( + + Id int PRIMARY key not null IDENTITY, + + TeacherName nvarchar(80) + +) + + + +go + +-- select * from Teachers + + + +insert into Teachers (TeacherName) values('张三') + +insert into Teachers (TeacherName) values('李四') + +insert into Teachers (TeacherName) values('王五') + + + +GO + + + +create table CourseInfo + +( + + Id int PRIMARY key not null IDENTITY, + + CourseName NVARCHAR(80) not null, + + TeacherId int not null + +) + + + +go + +-- select * from CourseInfo + + + +insert into CourseInfo (CourseName,TeacherId) values( '语文' , 2) + +insert into CourseInfo (CourseName,TeacherId) values( '数学' , 1) + +insert into CourseInfo (CourseName,TeacherId) values( '英语' , 3) + + + +GO + + + +create table StudentCourseScore + +( + + Id int PRIMARY key not null IDENTITY, + + StudentId int not null, + + CourseId int not null, + + Score int not null + +) + +go + +-- select * from StudentCourseScore + + + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='01') , 1 , 80) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='01') , 2 , 90) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='01') , 3 , 99) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='02') , 1 , 70) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='02') , 2 , 60) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='02') , 3 , 80) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='03') , 1 , 80) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='03') , 2 , 80) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='03') , 3 , 80) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='04') , 1 , 50) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='04') , 2 , 30) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='04') , 3 , 20) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='05') , 1 , 76) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='05') , 2 , 87) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='06') , 1 , 31) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='06') , 3 , 34) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='07') , 2 , 89) + +insert into StudentCourseScore (StudentId,CourseId,Score) values((select Id from StudentInfo where StudentCode='07') , 3 , 98) + + + +go +-- 练习题目: + +select *from CourseInfo +select *from StudentCourseScore +select *from StudentInfo +select *from Teachers + + +-- 1.查询"数学 "课程比" 语文 "课程成绩高的学生的信息及课程分数 + +select * from + (select * from StudentCourseScore where courseId = 1) as A + inner join StudentInfo s on s.Id = A.Id, + (select * from StudentCourseScore where CourseId = 2) as B + where A.Score > B.Score and A.StudentId = B.StudentId + + +-- 1.1 查询同时存在" 数学 "课程和" 语文 "课程的情况 + +select StudentId from StudentCourseScore + where CourseId = 1 or CourseId = 2 + group by StudentId + HAVING COUNT(distinct CourseId) = 2 + + +-- 1.2 查询存在" 数学 "课程但可能不存在" 语文 "课程的情况(不存在时显示为 null ) + +select * from + (select * from StudentCourseScore where CourseId = 2) A + left join (select * from StudentCourseScore where CourseId = 1) B on A.StudentId = B.StudentId + +-- 1.3 查询不存在" 数学 "课程但存在" 语文 "课程的情况 + +select * from + (select * from StudentCourseScore where CourseId = 1) A + left join (select * from StudentCourseScore where CourseId = 2) B on A.StudentId = B.StudentId + where B.CourseId is null + +-- 2.查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩 + +select Studentcode 学生编号,StudentName 学生姓名,AVG(Score) 平均成绩 from StudentCourseScore + inner join StudentInfo on StudentCourseScore.StudentId = StudentInfo.StudentCode + group by Studentcode,StudentName + HAVING AVG(Score) >= 60 + +-- 3.查询在 成绩 表存在成绩的学生信息 + +select * from StudentCourseScore + left join StudentInfo on StudentCourseScore.StudentId = StudentInfo.StudentCode + +-- 4.查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩(没成绩的显示为 null ) + +select StudentCode ,StudentName ,COUNT(CourseId) ,SUM(Score) from StudentCourseScore scs + right join StudentInfo si on scs.StudentId = si.StudentCode + group by StudentCode,StudentName + +-- 4.1 查有成绩的学生信息 + +select * from StudentCourseScore scs + inner join StudentInfo si on scs.StudentId = si.StudentCode + +-- 5.查询「李」姓老师的数量 + +select COUNT(TeacherName) from Teachers + where TeacherName like '李%' + +-- 6.查询学过 「张三」老师授课 的 同学的信息 + +select * from StudentCourseScore A + inner join CourseInfo B on A.CourseId = B.Id + inner join StudentInfo C on A.StudentId = C.StudentCode + inner join Teachers D on B.TeacherId = D.Id + where TeacherName = '张三' + +-- 7.查询没有学全所有课程的同学的信息 +select * from CourseInfo +select * from StudentCourseScore +select * from StudentInfo +select * from Teachers + +select StudentCode ,StudentName from StudentCourseScore A + inner join StudentInfo B on A.StudentId = B.StudentCode + group by StudentCode,StudentName + HAVING COUNT(CourseId) < (select COUNT(CourseName) from CourseInfo) + +-- 8.查询至少有一门课与学号为" 01 "的同学所学相同的同学的信息 + +select StudentCode ,StudentName from StudentCourseScore A + inner join StudentInfo B on A.StudentId = B.StudentCode + group by StudentCode ,StudentName + having count(CourseId) > 0 + +-- 9.查询和" 01 "号的同学学习的课程 完全相同的其他同学的信息 + +select StudentCode ,StudentName from StudentCourseScore A + inner join StudentInfo B on A.StudentId = B.StudentCode + group by StudentCode ,StudentName + having count(CourseId)=(select COUNT(CourseName) from CourseInfo) + +-- 10.查询没学过"张三"老师讲授的任一门课程的学生姓名 + +select distinct studentName from StudentCourseScore A + inner join CourseInfo B on A.CourseId = B.Id + inner join StudentInfo C on A.StudentId = C.StudentCode + inner join Teachers D on B.TeacherId = D.Id + where TeacherName != '张三' + + +-- 11.查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩 + + + +-- 12.检索" 数学 "课程分数小于 60,按分数降序排列的学生信息 + + + +-- 13.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 + + + +-- 14.查询各科成绩最高分、最低分和平均分: + + + +-- 15.以如下形式显示:课程 ID,课程 name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 + +/* + + 及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90 + + + + 要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列 + + + + 按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺 + +*/ + + + +-- 15.1 按各科成绩进行排序,并显示排名, Score 重复时合并名次 + + + +-- 16.查询学生的总成绩,并进行排名,总分重复时保留名次空缺 + + + +-- 16.1 查询学生的总成绩,并进行排名,总分重复时不保留名次空缺 + + + +-- 17.统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[60-0] 及所占百分比 + + + +-- 18.查询各科成绩前三名的记录 + + + +-- 19.查询每门课程被选修的学生数 + + + +-- 20.查询出只选修两门课程的学生学号和姓名 + + + +-- 21.查询男生、女生人数 + + + +-- 22.查询名字中含有「风」字的学生信息 + + + +-- 23.查询同名同性学生名单,并统计同名人数 + + + +-- 24.查询 1990 年出生的学生名单 + + + +-- 25.查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列 + + + +-- 26.查询平均成绩大于等于 85 的所有学生的学号、姓名和平均成绩 + + + +-- 27.查询课程名称为「数学」,且分数低于 60 的学生姓名和分数 + + + +-- 28.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况) + + + +-- 29.查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数 + + + +-- 30.查询不及格的课程 + + + +-- 31.查询课程编号为 01 且课程成绩在 80 分以上的学生的学号和姓名 + + + +-- 32.求每门课程的学生人数 + + + +-- 33.成绩不重复,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩 + + + +--34.成绩有重复的情况下,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩 + + + +-- 35.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩 + + + +-- 36.查询每门功成绩最好的前两名 + + + +-- 37.统计每门课程的学生选修人数(超过 5 人的课程才统计)。 + + + +-- 38.检索至少选修两门课程的学生学号 + + + +-- 39.查询选修了全部课程的学生信息 + + + +-- 40.查询各学生的年龄,只按年份来算 + + + +-- 41.按照出生日期来算,当前月日 < 出生年月的月日则,年龄减一 + + + +-- 42.查询本周过生日的学生 + + + +-- 43.查询下周过生日的学生 + + + +-- 44.查询本月过生日的学生 + + + +-- 45.查询下月过生日的学生 diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery3.sql" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery3.sql" new file mode 100644 index 0000000..724eefd --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery3.sql" @@ -0,0 +1,41 @@ +create database GoodsDB +go +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20), + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) +insert into GoodsType(TypeName) +select '服装内衣' union +select '鞋包配饰' union +select '手机数码' + +insert into GoodsInfo(GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TypeID) +select '提花小西装','红色','菲曼琪',300,1 union +select '百搭短裤','绿色','哥弟',100,1 union +select '无袖背心','白色' ,'阿依莲' ,700, 1 union +select '低帮休闲鞋','红色', '菲曼琪' ,900, 2 union +select '中跟单鞋','绿色', '哥弟' ,400 ,2 union +select '平底鞋','白色', '阿依莲', 200, 2 union +select '迷你照相机','红色' ,'尼康', 500 ,3 union +select '硬盘','黑色' ,'希捷' ,600 ,3 union +select '显卡','黑色' ,'技嘉',800 ,3 + +select * from GoodsInfo +select * from GoodsType + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称 ,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney=(select MAX(GoodsMoney) from GoodsInfo) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,min(GoodsMoney) 最低价格,MAX(GoodsMoney) 最高价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by typeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<600 \ No newline at end of file diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery4.sql" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery4.sql" new file mode 100644 index 0000000..5957396 --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery4.sql" @@ -0,0 +1,53 @@ +create database HOUSE_DB +on +( + name='HOUSE_DB', + filename='d:\temp\HOUSE_DB_mdf', + size=5, + maxsize=50, + filegrowth=1 +) +log on +( + name='HOUSE_DB_log', + filename='d:\temp\HOUSE_DB_log_ldf', + size=5, + maxsize=50, + filegrowth=1 +) +go +create table HOUSE_TYPE +( + type_id int not null primary key identity(1,1), + type_name varchar(50) not null, + +) +create table HOUSE +( + house_id int not null primary key identity(1,1), + house_name varchar(50) not null, + house_price float not null default(0), + type_id int not null references HOUSE_TYPE(type_id) +) + +insert into HOUSE_TYPE(type_name) +select '小户型' union +select '经济型' union +select '别墅' + +insert into HOUSE(house_name,house_price,type_id) +select '兴国型',500,1 union +select '小狗区',300,2 union +select '上都会型',1500,3 +--4、添加查询 +--查询所有房屋信息 +select * from HOUSE_TYPE +select * from HOUSE +--使用模糊查询包含”型“字的房屋类型信息 +select * from HOUSE where house_name like '%型' +--查询出房屋的名称和租金,并且按照租金降序排序 +select house_name 名称,house_price 租金 from HOUSE order by house_price desc +--使用连接查询,查询信息,显示房屋名称和房屋类型名称 +select house_name,type_name from HOUSE a inner join HOUSE_TYPE b on a.house_id=b.type_id +--查询所有房屋中月租最高的房屋,显示最高的租金和房屋名称 +select *from HOUSE where house_price=(select max(house_price) from HOUSE) diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery5.sql" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery5.sql" new file mode 100644 index 0000000..71abe84 --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/SQLQuery5.sql" @@ -0,0 +1,39 @@ +create database StarManagerDB +go +use StarManagerDB +go +create table StarType +( + T_NO int not null primary key identity(1,1), + T_NAME nvarchar(20) +) +create table StarInfo +( + S_NO int not null primary key identity(1,1), + S_NAME nvarchar(20) not null, + S_AGE int not null, + S_HOBBY nvarchar(20), + S_NATIVE nvarchar(20) default('中国大陆'), + S_T_NO int references StarType(T_NO) +) +insert into StarType(T_NAME) +select '体育明星' union +select 'IT明星' union +select '相声演员' + +insert into StarInfo(S_NAME,S_AGE,S_HOBBY,S_NATIVE,S_T_NO) +select '梅西',30,'射门','阿根廷',1 union +select '科比',35,'过人','美国',1 union +select '菜景观',40,'敲代码','中国',2 union +select '马克思',36,'造火箭','外星人',2 union +select '郭德纲',50,'相声','中国',3 union +select '黄铮',41,'拼多多','中国',2 + +select * from StarInfo +select * from StarType +--3、查询年龄最大的3个明星的姓名,特技和籍贯信息,要求使用别名显示列名。 +select top 3 S_NAME 姓名,S_HOBBY 特技,S_NATIVE 籍贯 from StarInfo order by S_AGE desc +--4、按 明星类型编号 分类查询 明星人数,明星平均年龄 ,显示明星人数大于2的分组信息,要求使用别名显示列名。 +select S_T_NO,count(*) 人数,AVG(S_AGE) from StarType a inner join StarInfo b on a.T_NO=b.S_T_NO group by S_T_NO HAVING COUNT(S_NAME)>2 +--5、查询明星类型为“体育明星”中年龄最大的姓名、特技、籍贯信息,要求显示列别名。 +select S_NAME,S_HOBBY,S_NATIVE,max(S_AGE) from StarInfo a inner join StarType b on a.S_T_NO=b.T_NO where S_AGE = (select MAX(S_AGE) from StarInfo where S_T_NO = 2) group by S_NAME,S_HOBBY,S_NATIVE \ No newline at end of file diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo1.java" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo1.java" new file mode 100644 index 0000000..f545794 --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo1.java" @@ -0,0 +1,35 @@ +package less; + +import java.util.Scanner; + +public class demo1 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + //* 需求:设计一个方法用于获取数组中元素的最大值 + // + //* 思路: + + //* ①定义一个数组,用静态初始化完成数组元素初始化 + //* ②定义一个方法,用来获取数组中的最大值,最值的认知和讲解我们在数组中已经讲解过了 + //* ③调用获取最大值方法,用变量接收返回结果 + //* ④把结果输出在控制台 + ////////////// + Scanner scan = new Scanner(System.in); + + int c=fangfa(); + System.out.println(c); + } + + public static int fangfa() { + int [] d=new int [] {99,100,65,75,80,94,92}; + int max; + max=d[0]; + for (int i = 0; i < d.length; i++) { + if (max d[i]) { + min = d[i]; + } + } + int e[] = new int[2]; + e[0] = max; + e[1] = min; + return e; + + } + +} diff --git "a/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo4.java" "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo4.java" new file mode 100644 index 0000000..98eda5c --- /dev/null +++ "b/\346\226\271\346\263\225\347\273\203\344\271\240/\346\270\251\345\271\277\347\224\237/demo4.java" @@ -0,0 +1,18 @@ +com.array.test; + +import java.util.Arrays; +import java.util.Scanner; + +//实现:在有序数组中插入一个元素 +// 对新数组排序---直接使用Arrays.sort()方法 +public class ArrayInsertTwo { + public static void main(String[] args) { + int[] arr=new int[]{5,8,19,20,23}; + System.out.println("原数组为:arr="+ Arrays.toString(arr)); + Scanner sc=new Scanner(System.in); + System.out.println("请输入插入的数据"); + arr[arr.length-1]=sc.nextInt(); //把要插入的数据放到数组的最后一个 + Arrays.sort(arr); + System.out.println("新数为:arr="+ Arrays.toString(arr)); + } +} \ No newline at end of file -- Gitee