2017年Java基礎筆試題
Java的主要工作是通過編程語言來製作互聯網頁面、製作動態效果以及網站等技術,現在網上關於這方面的教程有很多。下面是小編整理的關於Java基礎筆試題,希望大家認真閲讀!
1、 編寫程序,實現1到100之間整數的累加並輸出運算結果。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
s=s+i;
}
tln("1到100的累加和是"+s);
}}
2、編寫程序,計算1~100中奇數的累加和並輸出。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
if(i%2!=0)
s=s+i;
}
tln("1到100的奇數累加和是"+s);
}}
3、編寫程序,計算1~100中偶數的`累加和並輸出。
public class a
{
public static void main(String[] args)
{
int i,s=0;
for(i=1;i<=100;i++)
{
if(i%2==0)
s=s+i;
}
tln("1到100的偶數累加和是"+s);
}}
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);
-
Java數組定義常用方法
Java中的數組、是一種簡單的線性數據存儲結構、他用犧牲自動擴展大小來換取與集合相比的唯一優勢——查詢效率的提升。Java中的數組有什麼類型?我們要怎麼定義這些數組呢?下面跟yjbys小編一起來學習Java數組定義常用方法吧!java中有兩種數據類型:a)引...
-
Java開發崗位面試題「彙總」
下面是我自己收集整理的Java崗位今天面經遇到的面試題,可以用它來好好準備面試。Java基礎1.String類為什麼是final的。2.HashMap的源碼,實現原理,底層結構。3.説説你知道的幾個Java集合類:list、set、queue、map實現類咯。4.描述一下ArrayList和LinkedList各自實現...
-
Java中的運算符有哪些
java的運算符有算術運算符、關係運算符、賦值運算符、邏輯運算符、位運算符、條件運算符,下面我們一起來學習java運算符的詳細內容吧!1)、算術運算符運算符運算範例結果+正號+33-負號b=4;-b;-4+加5+510-減6-42*乘3*412/除5/51%取模(求餘)5%50++自增(前)a=2;b=++a;a=...
-
Java的位運算符和邏輯運算符
在許多古老的微處理器上,位運算比加減運算略快,通常位運算比乘除法運算要快很多。在現代架構中,情況並非如此:位運算的運算速度通常與加法運算相同(仍然快於乘法運算).下面小編準備了關於Java的位運算符和邏輯運算符,提供給大家參考!一.與、或、非、異或運算與0&am...