教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

java复习题有答案(2)

来源:网络收集 时间:2026-08-17
导读: public static void main(String args[]){ float x = 11; float y = 4; int z = (int) ( x/y ) ; switch ( z ){ case 1: x = x+1 ; case 2: x = x+2 ; default : x = x+3 ; } System.out.println(“Value of x : ”

public static void main(String args[]){ float x = 11; float y = 4;

int z = (int) ( x/y ) ; switch ( z ){ case 1:

x = x+1 ;

case 2:

x = x+2 ;

default :

x = x+3 ;

}

System.out.println(“Value of x : ” + x ); } }

输出结果为 。

41、class RectConstructor{

double length; double width;

RectConstructor(double a,double b) { length = a; width = b; }

double area() {

return length * width; } }

class RectDemo {

public static void main(String args[]) {

RectConstructor rect1 = new RectConstructor(5,10); RectConstructor rect2 = new RectConstructor(2,4); double ar;

ar = rect1.area();

System.out.println(\: \ar = rect2.area();

System.out.println(\: \} }

输出结果为

42.public class Practice{

public static void main (String[] args) { int i=0,j=1;

if((i++==1)||(j++==2)){ i=4; }

System.out.println(“i=”+i+”,j=”+j); } }

输出结果为:i= ,j=

43. import java.io.* ; public class DemoJava {

public static void main(String args[ ]) { int i , s = 0 ;

int a[ ]={1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9,10,11 ,12 };

for ( i = 0 ; i < a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(\ } }

输出结果为 。 44. class Parent{ void printMe( ){

System.out.println(”父类”); }

}

class Child extends Parent{ void printMe( ){

System.out.println(“子类”); }

void printAll( ){ super.printMe( ); this.printMe( );

printMe( ); } }

public class Test{

public static void main(String args[ ]){ Child myC=new Child( ); myC.printAll( ); } }

运行结果为:

45.public class ForDemo {

public static void main(String[] args){

int i,k;

for(k=2;k<=10;k++){ for(i=2;i

if(i= =k)

System.out.print (k+” ”); } }

}

输出结果为 。

46.设计一个类CalcuSum,计算并输出1~30中所有奇数的和。提示:用for循环或者While循环实现均可。

47.编写一个类名为MyApplet,分行显示自己姓名、性别、地址和电话的Applet程序,背景设为蓝色(blue)。

48.编写一个类名为Formula,求解一元二次方程根的图形用户界面应用程序,程序运行界面如下图所示。

49.编写一个Application程序,实现随机生成10个不大于100的整数,并求其平均值。

求解一元二次方程根的图形用户界面

提示:对于一元二次方程,如果b*b-4*a*c>=0, 则:xl=(-b+Math.sqrt(b*b-4*a*c))/2*a; x2=(-b-Math.sqrt(b*b-4*a*c))/2*a; 否则:无实根。

java复习题有答案(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/592195.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)