計算機語言Java考試模擬試題附答案
科學的未來只能是屬於勤奮而又謙虛的年輕一代!以下是小編為大家搜尋整理的計算機語言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);