程序设计题

上传人:简****9 文档编号:116408498 上传时间:2019-11-16 格式:DOC 页数:20 大小:133KB
返回 下载 相关 举报
程序设计题_第1页
第1页 / 共20页
程序设计题_第2页
第2页 / 共20页
程序设计题_第3页
第3页 / 共20页
程序设计题_第4页
第4页 / 共20页
程序设计题_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《程序设计题》由会员分享,可在线阅读,更多相关《程序设计题(20页珍藏版)》请在金锄头文库上搜索。

1、1、请写出完整的程序代码,定义一个类,类名为Test,求1到10的阶乘Public TestPublic static void main(String argv)Long result =1;For(int i =1;i=10;i+)result = result*i;System.out.println(“1到10的阶乘是:”+result);2、请写出完整的程序代码,类名为Test,利用for语句打印九九乘法表。Public TestPublic static void main(String argv)Long result =1;For(int i =1;i=9;i+)For(int

2、 j=1;j=i;j+)result = i*j;System.out.print(i+”*”+j+”=”+result + “t”);System.out.println(“”);3、请写出完整的程序代码,类名为Test,求1+2+3+100的奇数的和Public TestPublic static void main(String argv)Long result =1;For(int i =1;i=100;i+)if(i % 2 = 0)continue;result = result+i;System.out.println(“1到100奇数的和是:”+result);4. 编写子Ap

3、plication程序,实现求出1100之和public class abc public static void main(String args) for(int i=1,sum=0;i=100;i+) sum+=i; System.out.println(“sum=”+sum); 5编写子Application程序,实现1-100之间的偶数输出public class For public static void main(String args) for(int i=1; i=100;i+) if(i%2!=0) continue; System.out.println(“偶数”+i)

4、; 6创建一个桌子类table,该类中有桌子名称,重量,桌面宽度,长度和桌子高度属性,并含有以下几个方法。(1) 构造方法:初始化所有成员变量(2) area( ): 计算桌面地面积 (3) display(): 在屏幕上输出所有成员变量的值(4)changeweight(int w):改变桌子重量在main()方法中实现创建一个桌子对象,计算桌面地面积,改变桌子重量,并在屏幕上输出所有桌子地属性值public class table private String name;private int weight;private int length;private int width;priv

5、ate int height;public table()name=桌子;weight=100;length=10;width=10;height=10;public void dispaly()System.out.print(name=+name+weight=+weight+length=+length+width=+width+height=+height+n);int area()int area;area=length*width;return area;void changeweight(int w)weight=w;/return weight;public static vo

6、id main(String args) / TODO Auto-generated method stubtable ta =new table();ta.dispaly();int x;x=ta.area();System.out.print(面积=+x+n);ta.changeweight(10);ta.dispaly();、程序设计题1、public class Sum public static void main( String args ) double sum = 0.0 ; for ( int i = 1 ; i = 100 ; i + + ) sum += 1.0/(dou

7、ble) i ; System.out.println( sum=+sum ); 答:计算 1/1+1/2+1/3+.+1/100 的值2、 import java.io.* ; public class Reverse public static void main(String args ) int i , n =10 ; int a = new int10; for ( i = 0 ; i = 0 ; i ) System.out.print(ai+ ); System.out.println( ); 答:从标准输入(键盘)读入10个整数存入整型数组a中,然后逆序输出这10个整数3、 i

8、mport java.awt.*; public class abc public static void main(String args) new FrameOut(); class FrameOut extends Frame / Frame为系统定 Button btn; / 义的窗框类 FrameOut( ) super(按钮); btn = new Button(按下我); setLayout(new FlowLayout( ); add(btn); setSize(300,200); show( ); 答:创建一个标题为按钮的窗框,窗框中显示有按下我字样的按钮。4、import

9、java.io.*; public class abc public static void main(String args) SubClass sb = new SubClass( ); System.out.println(sb.max( ); class SuperClass int a = 10 , b = 20 ; class SubClass extends SuperClass int max( ) return (ab)?a:b); 答:求两个数的最大值。四、写出下面程序的运行结果(每小题10分,共30分)1、 import java.io.*;public class ab

10、c public static void main(String args ) AB s = new AB(Hello!,I love JAVA.); System.out.println(s.toString( ); class AB String s1; String s2; AB( String str1 , String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2;答:1、Hello! I love JAVA.2、 import java.io.* ; public class abc public static void main(String args ) int i , s = 0 ; int a = 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ; for ( i = 0 ; i a.length ; i + ) if ( ai%3 = = 0 ) s += ai ; System.out.println(s=+s); 答:s = 1803、import java.io.* ; public class abc

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号