欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > java >内容正文

java

《Java程序设计》实验报告——Java的基本程序设计结构

发布时间:2024/10/5 java 46 豆豆
生活随笔 收集整理的这篇文章主要介绍了 《Java程序设计》实验报告——Java的基本程序设计结构 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

浙江理工大学

Java程序设计》

 实验报告

 20 19~20 20学年第 1学期     

 

信息学院

 

计算机科学技术183

 

申屠志刚

 

2018329621200

任课教师

任祝

( 第4周 周二 345节)

   计算机科学技术专业

20 19 年 9 月

《Java程序设计》实 验 报 告(一)

实验名称:Java的基本程序设计结构

实验地点:10-306

所使用的工具软件及环境:

JDK1.7或1.8与Eclipse

 

 

一、实验目的:

熟悉Java开发环境,建立Java工程,练习编程,会使用变量,字符串,数组,输入与输出等API。

 

二、实验内容:

  • 利用eclipse建立Java工程
  • 必做题
  • (1)编程实现浙大ACM题库中1001(Calculate a + b),目的是学会JAVA开发环境搭建

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1001

    1001:calculate a+b

     

  • 选做题,从下列题目中选择2题
  • (1)编程实现浙大ACM题库中1048(Financial Management),具体见“实验1-题目3(1).pdf”

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1048

    (2)编程实现浙大ACM题库中1292(Integer Inquiry),具体见“实验1-题目3(2).pdf”

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1292

    (3)编程实现浙大ACM题库中1338(Up and Down Sequences),具体见“实验1-题目3(3).pdf”

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1338

     

    三、要求:

    (1)说明原理

    ZOJ 1001

    简单JAVA程序设计

    ZOJ 1048

    简单JAVA程序计算应用

    ZOJ 1292

    JAVA Biginteger类应用

    ZOJ 1338

    复杂模拟编程

    (2)源代码

    ZOJ 1001

    import java.io.*;

    import java.math.*;

    import java.util.*;

    import java.text.*;

     

    class Main{

    public static void main(String[] args) {

        Scanner cin = new Scanner (System.in);

            int a, b;

            while(cin.hasNext()){

                a = cin.nextInt();

                b = cin.nextInt();

                System.out.println(a+b);

            }

    }

    }

    ZOJ 1048

    import java.io.*;

    import java.math.*;

    import java.util.*;

    import java.text.*;

     

    class Main{

    public static void main(String[] args) {

        Scanner cin = new Scanner (System.in);

            float sum=0;

        for(int i=0;i<12;i++) {

            sum+=cin.nextFloat();

        }

            System.out.printf("$%.2f",(sum/12));

            System.out.println();

           

    }

    }

    ZOJ 1292

    import java.io.*;

    import java.math.*;

    import java.util.*;

    import java.text.*;

     

    class Main{

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int N=sc.nextInt();//块的个数

        int i=0;

        while(i<N){//输入每一块

            BigInteger sum;

            sum=BigInteger.valueOf(0);

            while(sc.hasNextBigInteger()){

                //s=sc.nextLine();//获得下一行

                BigInteger b=sc.nextBigInteger();

                if(b.equals(BigInteger.ZERO)){

                    System.out.println(sum);

                    if(i!=N-1)System.out.println();

                    break;

                }

                sum=sum.add(b);

            }

            i++;

        }

    }

    }

    ZOJ 1338

    import java.io.*;

    import java.util.*;

     

    class Main{

    public static void main(String[] args) {

        Scanner cin = new Scanner (System.in);

        int a[]=new int[102];

        int x,i,j,u,d,t,fu,fd,nu,nd;

        while(cin.hasNextInt()){

        x=cin.nextInt();

        if(x==0)break;

            a[0]=x;

            j=1;

            while(cin.hasNextInt()) {

            x=cin.nextInt();

            if(x==0)break;

            a[j++]=x;

            }

            u=d=nu=nd=t=0;

            fu=fd=0;

            for(i=0;i<j-1;i++){

                if(a[i]==a[i+1]){

                    if(fu==0&&fd==0)

                    t++;

                    if(fu!=0)

                    u++;

                    if(fd!=0)

                    d++;

                }

                if(a[i]<a[i+1]){

                    fd=0;

                    if(fu==0){

                        fu=1;

                        nu++;

                    }

                    u++;

                    u+=t;

                    t=0;

                }

                if(a[i]>a[i+1]) {

                    fu=0;

                    if(fd==0){

                        fd=1;

                        nd++;

                    }

                    d++;

                    d+=t;

                    t=0;

                }

            }

            double m,n;

            if(nu==0)

            n=0.0;

            else

            n=(double)u/nu;

            if(nd==0)

            m=0.0;

            else

            m=(double)d/nd;

            System.out.printf("Nr values = %d:  %.6f %.6f\n",j,n,m);

        }

    }

    }

    (3)结果截图

    ZOJ 1001

    ZOJ 1048

    ZOJ 1292

     

    ZOJ 1338

    四、实验收获与体会:

    搭建与熟悉Java开发环境,学会建立Java工程,练习简单编程。

    学会使用各种变量类型,字符串,数组,标准输入与输出等API。

    学会JAVA Biginteger类简单操作与应用。

        利用JAVA语言解决较复杂的程序问题。

     

     

     

    总结

    以上是生活随笔为你收集整理的《Java程序设计》实验报告——Java的基本程序设计结构的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。