糯米文學吧

位置:首頁 > 計算機 > java語言

計算機二級考試Java模擬試題及答案2017

java語言1.57W

不積跬步,何以至千里。試題的規律都是從一點一滴積累而來。下面是小編整理的計算機二級考試Java模擬題及答案,歡迎練習!

計算機二級考試Java模擬試題及答案2017

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);

}

}