JAVA环境配置+考试题目+Android studio配置与入门教程.docx

上传人:b****3 文档编号:12624048 上传时间:2023-04-21 格式:DOCX 页数:24 大小:974.74KB
下载 相关 举报
JAVA环境配置+考试题目+Android studio配置与入门教程.docx_第1页
第1页 / 共24页
JAVA环境配置+考试题目+Android studio配置与入门教程.docx_第2页
第2页 / 共24页
JAVA环境配置+考试题目+Android studio配置与入门教程.docx_第3页
第3页 / 共24页
JAVA环境配置+考试题目+Android studio配置与入门教程.docx_第4页
第4页 / 共24页
JAVA环境配置+考试题目+Android studio配置与入门教程.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

JAVA环境配置+考试题目+Android studio配置与入门教程.docx

《JAVA环境配置+考试题目+Android studio配置与入门教程.docx》由会员分享,可在线阅读,更多相关《JAVA环境配置+考试题目+Android studio配置与入门教程.docx(24页珍藏版)》请在冰豆网上搜索。

JAVA环境配置+考试题目+Android studio配置与入门教程.docx

JAVA环境配置+考试题目+Androidstudio配置与入门教程

1、java环境配置--2张图

运行窗口分别输入java–version、java

2、eclipse创建第一个项目并启动--2张图

创建project界面,创建class界面

3、编写一个Java程序,使用数组存放录入的6件商品名称、数量和价格,然后使用下标访问第6个商品名称、数量和价格、最后再输出所有的商品名称、数量和价格。

packageaasd;

importjava.util.Scanner;

publicclassasd{

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

doublesum=0;

double[]prices=newdouble[6];//声明数组并分配空间

double[]shuliang=newdouble[6];

int[]number=newint[6];

String[]name=newString[6];

Scannerinput=newScanner(System.in);//接收用户从控制台输入的数据

for(inti=0;i

System.out.println("请输入第"+(i+1)+"商品名称:

");

name[i]=input.next();

}

for(inti=0;i

System.out.println("请输入第"+(i+1)+"商品数量:

");

shuliang[i]=input.nextDouble();

}

for(inti=0;i

System.out.println("请输入第"+(i+1)+"商品价格:

");

prices[i]=input.nextDouble();//接收用户从控制台输入的数据

sum=sum+prices[i];

}

System.out.println("第6件商品的名称为:

"+name[5]);

System.out.println("第6件商品的价格为:

"+prices[5]);

for(inti=0;i<6;i++){

System.out.println("第"+(i+1)+"件商品的名称:

"+name[i]+"数量:

"+shuliang[i]+"价格:

"+prices[i]);

}

}

}

4、Java字符串拼接、获取字符串长度、字符串大小写转换、去除字符串中的空格、字符串的替换、字符串比较

packageaasd;

importjava.util.Scanner;

publicclassasd{

 

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

Stringstr1="yh";

Stringstr2="Tcz,M";

System.out.println("字符串拼接"+str1.concat(str2));

System.out.println("字符串长度:

"+str1.length());

System.out.println("转小写:

"+str1.toLowerCase());

System.out.println("转大写:

"+str2.toUpperCase());

System.out.println("去除空格"+str1.trim());

System.out.println("提取子字符串"+str1.substring(0,2));

String[]arr1=str2.split(",");

System.out.println("分割字符串");

for(inti=0;i

System.out.println(arr1[i]);

}

Stringst1="yh";

Stringst2="CM";

System.out.println("字符串替换"+str2.replace("M","b"));

System.out.println("字符串比较"+st1.equalsIgnoreCase(st2));

System.out.println("字符串查找"+str2.indexOf('M'));

System.out.println("颜寒");

}

5.编写一个Java程序,假设有一个矩阵为6行6列,该矩阵是由程序随机产生的16-99以内数字排列而成。

packageqwer;

publicclassavbn{

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

int[][]x=newint[5][5];

inta=16,b=99;

for(inti=0;i

{

for(intj=0;j

{

x[i][j]=(int)a+(int)(Math.random()*(b-a));

System.out.print(x[i][j]+"");

}

System.out.print("\n");

}

System.out.print("颜寒");}}

6、要求:

1、用户输入6组商品名称、数量、价格;

2、输出商品的平均价格、最大最小价格

3、商品信息根据数量升序排序后输出来。

packageyh;

importjava.util.Scanner;

publicclassqwe{

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

inti;

int[]price=newint[6];

String[]name=newString[6];

int[]shuliang=newint[6];

Scannerinput=newScanner(System.in);//接收用户从控制台输入的数据

for(i=0;i<6;i++){

System.out.println("请输入第"+(i+1)+"件商品的名称:

");

name[i]=input.next();//接收用户从控制台输入的数据

System.out.println("请输入第"+(i+1)+"件商品的价格:

");

price[i]=input.nextInt();//接收用户从控制台输入的数据

System.out.println("请输入第"+(i+1)+"件商品的数量:

");

shuliang[i]=input.nextInt();//接收用户从控制台输入的数据

}

System.out.print("\n");

intsum=0;intj;

for(j=0;j<6;j++)

sum=sum+price[j];

System.out.println("商品总价格为"+sum);

intavg;

avg=sum/6;

System.out.println("商品均价为"+avg);

intmax;max=price[0];

intmin;min=price[0];

for(intm1=0;m1

{

if(price[m1]>max)

max=price[m1];

if(price[m1]

min=price[m1];

}

System.out.println("最大价格"+max+"最小价格"+min);

for(intm=0;m

for(intn=m+1;n

{

if(shuliang[m]>shuliang[n])

{

inttemp=shuliang[m];

shuliang[m]=shuliang[n];

shuliang[n]=temp;

}

}

}

for(intx=0;x

System.out.println("数量"+shuliang[x]+"价格"+price[x]+"名称"+name[x]);

}

System.out.println("颜寒");

}

}

 

7.在注册时,需要验证用户输入的用户名、密码、性别、年龄等信息是否符合标准,如果符合标准方可进行注册。

packageyh;

importjava.util.Date;

importjava.util.Scanner;

publicclassyh{

publicstaticvoidmain(String[]args){

Datefirst=newDate();

Stringusername;

Stringpwd;

inti=0;

intj=0;

while(true)

{

Scannerinput=newScanner(System.in);

//input.useDelimiter("\n");

System.out.println("------------用户注册--------------");

System.out.println("用户名:

");

username=input.nextLine();

System.out.println("密码:

");

pwd=input.nextLine();

System.out.println("性别:

");

Stringsex=input.nextLine();

System.out.println("年龄:

");

Stringage=input.nextLine();

booleancon=Register.validateUser(username,pwd,sex,age);

if(con){

System.out.println("注册成功!

");

break;

}else{

System.out.println("注册失败!

");

j++;

if(j>2){

System.out.println("输入次数超过3次,等待20秒后再次尝试输入。

");

Datedate1=newDate();//获取当前日期

System.out.println("[发生错误时间]"+date1);

try{

Thread.sleep(2000);//暂停20秒

}catch(InterruptedExceptione){

e.printStackTrace();

}

Datedate2=newDate();

j=0;

System.out.println("现在时间为:

"+date2);

System.out.println("请重新输入:

");

}

}

}

while(true)

{

Scannerinput=newScanner(System.in);

System.out.println("------------用户登陆--------------");

System.out.println("用户名:

");

Stringlogin_name=input.nextLine();

System.out.println("密码:

");

Stringlogin_pwd=input.nextLine();

booleancen=Register.validateLogin(login_name,login_pwd,username,pwd);

if(cen){

System.out.println("登录成功!

");

break;

}else{

System.out.println("用户名或密码有误!

");

i++;

if(i>2){

System.out.println("输入次数超过3次,等待20秒后再次尝试输入。

");

Datedate1=newDate();//获取当前日期

System.out.println("[发生错误时间]"+date1);

try{

Thread.sleep(20000);//暂停20秒

}catch(InterruptedExceptione){

e.printStackTrace();

}

Datedate2=newDate();

i=0;

System.out.println("现在时间为:

"+date2);

System.out.println("请重新输入:

");

}

}

}

Datelast=newDate();

System.out.println("运行时间:

"+(last.getTime()-first.getTime())/1000+"秒");

}

}

packageyh;

publicclassRegister{

publicstaticbooleanvalidateUser(Stringuname,Stringupwd,Stringsex,Stringage){

booleanconUname=false;//用户名是否符合要求

booleanconPwd=false;//密码是否符合要求

booleanconAge=false;//年龄是否符合要求

booleanconsex=false;//性别是否符合要求

booleancon=false;//验证是否通过

Stringsexm="男";

Stringsexw="女";

if(uname.length()>0){

for(inti=0;i

//验证用户名是否全部为字母,不能含有空格

if(Character.isLetterOrDigit(uname.charAt(i))){

conUname=true;

}else{

conUname=false;

System.out.println("用户名只能由字母组成,且不能含有空格!

");

break;

}

}

}else{

System.out.println("用户名不能为空!

");

}

if(upwd.length()>0){

for(intj=0;j

//验证密码是否由数字和字母组成,不能含有空格

if(Character.isLetterOrDigit(upwd.charAt(j))){

conPwd=true;

}else{

conPwd=false;

System.out.println("密码只能由数字或字母组成!

");

break;

}

}

}else{

System.out.println("密码不能为空!

");

}

if(sex.length()>0){

if(sex.equals(sexm)||sex.equals(sexw)){

consex=true;

}else{

consex=false;

System.out.println("仅可输入“男”和“女”!

");

}

}else{

System.out.println("性别不能为空!

");

}

if(age.length()>0){

for(intk=0;k

//验证年龄是否由数字组成

if(Character.isDigit(age.charAt(k))){

conAge=true;

}else{

conAge=false;

System.out.println("年龄输入有误!

");

break;

}

}

}else{

System.out.println("年龄必须输入!

");

}

if(conUname&&conPwd&&conAge&&consex){

con=true;

}else{

con=false;

}

returncon;

}

publicstaticbooleanvalidateLogin(Stringlogin_name,Stringlogin_pwd,Stringuname,Stringupwd){

booleancon=false;

if(uname.equals(login_name)&&upwd.equals(login_pwd)){//比较两个String对象

con=true;

}else{

con=false;

}

returncon;

}

}

要求:

1、用户名、密码可以是字母+数字,但是不能有空格以及其他字符,在登录过程中字母全部转换为小写或者忽略大小写。

2、性别、年龄需要符合要求,比如性别只能是“男”或者“女”,年龄只能是数字。

3、如果注册过程中有一个不合格,提示信息、稍等30秒后可以循环注册直至成功。

4、注册成功后需要登录一下,同时加上时间的计算。

在登录时,需要验证用户输入的用户名、密码以及年龄信息是否符合标准,如果符合标准方可进行登录。

----------------------------------------------------------------15分;

要求:

1、用户名、密码可以是字母+数字,但是不能有空格,字母全部转换为小写。

2、年龄需要大于18小于50。

3、如果登录过程中有一个不合格,提示信息,超过3次后需要等待10秒才可以循环登录直至成功。

packageyh;

importjava.util.Scanner;

publicclassaaa{

 

publicstaticvoidmain(String[]args){

Datefirst=newDate();

Stringusername;

Stringpwd;

inti=0;

intj=0;

while(true)

{

Scannerinput=newScanner(System.in);

//input.useDelimiter("\n");

System.out.println("------------用户注册--------------");

System.out.println("用户名:

");

username=input.nextLine();

System.out.println("密码:

");

pwd=input.nextLine();

System.out.println("性别:

");

Stringsex=input.nextLine();

System.out.println("年龄:

");

Stringage=input.nextLine();

booleancon=Register.validateUser(username,pwd,sex,age);

if(con){

System.out.println("注册成功!

");

break;

}else{

System.out.println("注册失败!

");

j++;

if(j>2){

System.out.println("输入次数超过3次,等待20秒后再次尝试输入。

");

Datedate1=newDate();//获取当前日期

System.out.println("[发生错误时间]"+date1);

try{

Thread.sleep(20000);//暂停20秒

}catch(InterruptedExceptione){

e.printStackTrace();

}

Datedate2=newDate();

j=0;

System.out.println("现在时间为:

"+date2);

System.out.println("请重新输入:

");

}

}

}

while(true)

{

Scannerinput=newScanner(System.in);

System.out.println("------------用户登陆--------------");

System.out.println("用户名:

");

Stringlogin_name=input.nextLine();

System.out.pri

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 小升初

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1