計算機二級考試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中如何獲取Spring中配置的bean
Spring是一個分層的JavaSE/EEfull-stack(一站式)輕量級開源框架。在Java中如何獲取Spring中配置的'bean?下面本站小編帶大家一起來看看詳細操作,希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試網!一、什麼是Spring?Spring是一個輕量級的控...
-
全國計算機等級《二級JAVA》命題預測試卷
以下是本站小編帶來的全國計算機等級《二級JAVA》命題預測試卷,歡迎學習!更多內容請關注應屆畢業生考試網!1、軟件生命週期是指()。A.軟件產品從提出、實現、使用維護到停止使用退役的過程B.軟件從需求分析、設計、實現到測試完成的過程,C.軟件的開發過程D.軟件...
-
Java語法基礎for語句練習
本文是本站小編搜索整理的關於Java語法基礎for語句練習,供參考學習,希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試網!控制語句——for練習語句的嵌套應用累加求和,計數器循環嵌套一、語句的嵌套應用語句嵌套形式。其實就是語句中...
-
計算機二級JAVA考試構建JAVA程序2017
很多人一見到説要編程就以為很難,其實只有一點一滴學知識點也不難,下面是小編整理的計算機二級JAVA考試構建JAVA程序介紹,歡迎閲讀!第一個javaapplicationjava程序分為javaapplication(java應用程序)和javaapplet(java小應用程序)兩種。下面讓我們編寫一個java應...