• 第三周课程总结&实验报告一


    1.打印输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其中各位数字立方和等于该数本身。例如,153是一个“水仙花数”。
    package project1;

    public class test { public static void main(String[] args) {

    for(int num=100;num<1000;num++)
    {
    	int i=num%10;
    	int j=num/10%10;
    	int k=num/100%10;
    	if(i*i*i+j*j*j+k*k*k==num)
    	{
    		System.out.println(num);
    	}
    }
    

    }

    }


    2. 编写Java程序,求13-23+33-43+…+973-983+993-1003的值。
    package project1;

    public class test2 {
    public static void main(String[] args) {
    int a=13;
    int b=0;
    int c=10;
    int sum=0;
    System.out.println("a的值 "+"b的值 "+"sum的值");
    do {
    if(b%2==0) {
    sum+=a;
    System.out.println(a+" "+b+" "+sum);
    }else {
    sum-=a;
    System.out.println(a+" "+b+" "+sum);
    }
    a+=c;
    b++;
    }while(a<=1003);
    System.out.println("最终结果为:"+sum);
    }

    }


    3. 编程求1!+2!+3!+…+20!。
    package project1;

    public class test3 {
    public static void main(String[] args) {
    long resu20=mults(20);
    System.out.println("(1!+2!+3!+......+20!)的最终结果是:"+resu20);
    }
    public static long mults(long x) {
    int temp=1;
    int sum=0;
    for(int i=1;i<=x;i++) {
    temp*=i;
    sum+=temp;
    }
    return sum;
    }
    }


    4. 编写Java程序,计算8+88+888+…前10项之和。
    package project1;

    public class test5 {
    public static void main(String[] args) {
    long a,b=0,c=0;
    System.out.println("结果为");
    for(a=1;a<=10;a++) {
    b=b*10+8;
    c+=b;
    }
    System.out.print(c);
    }
    }

    5. 一个数如果恰好等于它的因子之和,这个数就称为完数。编写程序输出1000以内的所有完数。
    package project1;

    public class test4 {
    public static void main(String[] args) {
    WanShu ws=new WanShu();
    ws.print();
    }

    }
    class WanShu{
    public void print() {
    int s;
    for(int i=6;i<=1000;i++) {
    s=0;
    for(int j=1;j<i;j++) {
    if(i%j0)
    s+=j;
    }
    if(i
    s)
    System.out.println("完全数为:"+i);
    }
    }
    }


    6. 编写应用程序,输出满足1+2+3+…+n<8888的最大正整数。
    package project1;

    public class test6 {
    public static void main(String[] args) {
    boolean flag=true;
    int n=0;
    int t=0;
    while(flag) {
    t+=n+1;
    if(t>=8888) {
    flag=false;
    }
    n++;
    }
    System.out.println("===="+n);
    }

    }


    7. 使用for循环打印下面的图(等腰三角形)
    package project1;

    public class test7 {
    public static void main(String[] args) {
    String a="*";
    String b="";
    int count=5;
    for(int temp=1;temp<(count+1);temp++) {
    if(temp!=1) {
    a+=" *";
    }
    b=trans(count,temp,a);
    System.out.println(b);
    }
    }
    private static String trans(int count,int temp,String a) {
    String b=a;
    for(int temp2=count;temp2>temp;temp2--) {
    b=" "+b;
    }
    return b;
    }

    }


    本周总结:感觉还行吧,不会感觉作业太难,知识在运用eclipse时不太熟练,但以后会越用越熟练的。

  • 相关阅读:
    wapp HTTP Error 404. The requested resource is not found.
    JS 动态修改json字符串
    使用VS2017新建的Web项目报错:Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1
    java park unpark
    DOUHAO
    Thread dump
    线程状态
    https://stackoverflow.com/questions/20795295/why-jstack-out-says-thread-state-is-runnable-while-socketread
    rocketmq-flink
    the-implementation-of-epoll
  • 原文地址:https://www.cnblogs.com/chenzg90826/p/11520698.html
Copyright © 2020-2023  润新知