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中,我们可以利用程序获取当前的'系统时间,那么你知道该怎么获取吗?下面跟yjbys小编一起来学习一下吧!一、获取当前系统时间和日期并格式化输出:import;importleDateFormat;publicclassNowString{publicstaticvoidmain(String[]args){SimpleDateFormatdf=ne...
-
Java命令参数说明大全
为了提高性能,往往需要调整java命令参数,以求系统达到最佳新能。另外这些参数的配置也是影响系统稳定性的一个重要因素,相信大多数Java开发人员都见过OutOfMemory类型的错误。这其中很可能就是JVM参数配置不当或者就没有配置没意识到配置引起的。那么java命令参数...
-
Java中日期的处理方法
Java语言的Calendar(日历),Date(日期),和DateFormat(日期格式)组成了Java标准的一个基本但是非常重要的部分。日期是商业逻辑计算一个关键的部分。下面小编准备了关于Java中日期的处理方法,欢迎大家参考!我们将讨论下面的类:1、具体类(和抽象类相对)2、抽象类Forma...
-
Java工程师面试题及答案
现在就快到企业的招聘季了,你们准备好去面试了吗?今天小编收集了一些面试中常会问道的问题给大家,希望能给大家带来帮助哦!也祝各位同学都能找到让自己满意的工作!1.如何判断一个数是2的幂。个人认为,数字转化为二进制,符号位为0,余下部分有且只有最左边一位是1,其余...