计算机二级考试Java模拟试题及答案2017
不积跬步,何以至千里。试题的规律都是从一点一滴积累而来。下面是小编整理的计算机二级考试Java模拟试题及答案,欢迎练习!
1、编写程序,计算下列分段函数的值。
x? (x>=0)
y=
-x? (x<0)
import .*;
public class testa
{ public static void main(String[] args) throws IOException
{
float? x,y;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("请输入x:");
String temp=Line();
x = eFloat(temp);
if(x>=0)
{
y=x;
}else
{
y=-x;
}
tln("y="+y);
}
}
2、根据年龄,判断某人是否为成年。
import .*;
public class testa
{
public static void main(String[] args) throws IOException
{
int x;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("请输入x:");
String temp=Line();
x = eFloat(temp);
if(x>=18)
{
tln("成年人");
}
if(x<18)
{
tln("未成年");
}
}
}
3、判断2020的奇偶性,并进行输出。
public class test
{
public static void main(String[] args)
{
int x;
x=2020;
if(x%2==0)
tln(+x+"是偶数");
else
tln(+x+"不是偶数");
}
}
4、比较两个数的`大小,找出其中的最大数并输出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
m=0;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("请输入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("请输入y:");
String tempy=Line();
y= eFloat(tempy);
if(x>y)
{
m=x;
}else
{
m=y;
}
tln("最大数为"+m);
}
}
5、比较两个数的大小,找出其中的最小数并输出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
m=0;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("请输入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("请输入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
m=x;
}else
{
m=y;
}
tln("最小数为"+m);
}
}
6、编写一个Java程序,判断某年份是否为闰年。
import .*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("请输入x:");
String temp=Line();
x =eFloat(temp);
if(x@0==0)
{
tln(+x+"是闰年");
}
else
if(x%4==0)
{
tln(+x+"是闰年");
}
else{ tln(+x+"不是闰年");}
}
}
7、比较两个数的大小,找出其中的最大数和最小数并输出。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("请输入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("请输入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
tln("最小数为"+x);
tln("最大数为"+y);
}else
{
tln("最小数为"+y);
tln("最大数为"+x);
}
}
}
8、比较两个数的大小,找出其中的最大数和最小数,并输出最大数和最小数之差。
import .*;
public class ka
{ public static void main(String[] args) throws IOException
{
float? x,y,m;
InputStreamReader readerx=new InputStreamReader();
BufferedReader inputx=new BufferedReader(readerx);
tln("请输入x:");
String tempx=Line();
x = eFloat(tempx);
InputStreamReader readery=new InputStreamReader();
BufferedReader inputy=new BufferedReader(readery);
tln("请输入y:");
String tempy=Line();
y= eFloat(tempy);
if(x{
tln("最小数为"+x);
tln("最大数为"+y);
m=y-x;
tln("最大数与最小数之差为"+m);
}else
{
tln("最小数为"+y);
tln("最大数为"+x);
m=x-y;
tln("最大数与最小数之差为"+m);
}
}
}
9、编写程序,计算下列分段函数的值。
x? (x>0)
y=???? 0? (x=0)
-x? (x<0)
import .*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x,y;
y=0;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("请输入x:");
String temp=Line();
x = eFloat(temp);
if(x>0)
{
y=x;
}
if(x==0)
{
y=0;
}
if(x<0)
{
y=-x;
}
tln("y="+y);
}
}
10、编写程序,计算下列分段函数的值。
x-1? (x>1)
y=???? 0? (-1≤x≤1)
x+10? (x<-1)
import .*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x,y;
y=0;
InputStreamReader reader=new InputStreamReader();
BufferedReader input=new BufferedReader(reader);
tln("请输入x:");
String temp=Line();
x = eFloat(temp);
if(x>1)
{
y=x-1;
}
if(1.0>=x&&x>=-1.0)
{
y=0;
}
if(x<-1)
{
y=x+10;
}
tln("y="+y);
}
}
-
Java类加载器类介绍
类加载器是Java语言的一个创新,也是Java语言流行的重要原因之一。它使得Java类可以被动态加载到Java虚拟机中并执行。以下是小编为大家搜索整理的java类加载器,希望能给大家带来帮助!更多精彩内容请及时关注我们。类加载器:java虚拟机中可以安装多个类加载,系统默...
-
Java虚拟机垃圾收集算法
Java虚拟机的内存区域中,程序计数器、虚拟机栈和本地方法栈三个区域是线程私有的,随线程生而生,随线程灭而灭;栈中的栈帧随着方法的进入和退出而进行入栈和出栈操作,每个栈帧中分配多少内存基本上是在类结构确定下来时就已知的,因此这三个区域的内存分配和回收都具...
-
2017计算机二级考试Java练习题及答案
以下是应届毕业生考试网小编整理的2017年计算机二级考试Java练习题及答案,供考生参考。更多计算机等级考试相关信息请关注应届毕业生计算机等级考试网。1[单选题]下列方法被调用后,一定使调用线程改变当前状态的是()。fy()d()p()ive()参考答案:C参考解析:线程调用s...
-
Java编程语言初学者入门课程
初学者先弄清这些Java的基本概念也是必不可少的,死记硬背肯定是不行的,重在理解,理解它们之间的区别与联系,分别有哪些应用。希望对您有所帮助!更多内容请关注应届毕业生考试网!一、先明白了解什么是Java的四个方面。初学者先弄清这些Java的基本概念也是必不可少的...