zoukankan      html  css  js  c++  java
  • Java暑期学习第三十八天日报

    一、今日学习内容:

    练习上学期讲课过程中的例题。

    二、遇到的问题:

    无。

    三、明日计划:

    明天继续练习例题。

    今天练习的具体内容如下:

    第一讲

    1.科学计数法的表示

    import java.util.Scanner;
    import java.text.DecimalFormat;  //设置小数位数
    public class t2 {
        public static void main(String[] args) {
            double x;
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入一个浮点数:");
            x=sc.nextDouble();
            DecimalFormat df=new DecimalFormat("0.####E0");
            System.out.println("该数的科学计数法形式为:"+df.format(x));
            System.exit(0);        
        }        
    }

    测试截图:

    第二讲 C和c++的差异

    例1.逆序输出

    import java.util.Scanner;
    import java.text.DecimalFormat;  //设置小数位数
    public class t2 {
        public static void main(String[] args) {
            int i,n=0;
            Scanner sc=new Scanner(System.in);
            System.out.println("How many numbers would you like to type?");
            n=sc.nextInt();
            int []p=new int[n];
            if(p==null)
                System.out.println("Error: memory could not be allocated");
            else {
                System.out.println("Please input these ingter:");    
            for(i=0;i<n;i++) {
                p[i]=sc.nextInt();
            }
            System.out.println("The result is:");
            for(i=n-1;i>=0;i--) {
                System.out.print(p[i]+" ");
            }
            }
             
            System.exit(0);        
        }        
    }

    测试截图:

    例2,转置矩阵

    import java.util.Scanner;
    import java.text.DecimalFormat;  //设置小数位数
    public class t2 {
        public static void main(String[] args) {
            int i,j,row=0,col=0;
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入行和列:");
            row=sc.nextInt();
            col=sc.nextInt();
            int [][]p=new int [row][col];
            System.out.println("请输入一个二维矩阵:");
            for(i=0;i<row;i++)
                for(j=0;j<col;j++) {
                    p[i][j]=sc.nextInt();
                }
            System.out.println("该矩阵的转置矩阵是:");
            for(j=0;j<col;j++) {
                for(i=0;i<row;i++) {
                    System.out.print(p[i][j]+" ");
                }
                System.out.println();
            }
            System.exit(0);        
        }        
    }

    测试截图:

    例3,引用传递

    public class t2 {
        public static void main(String[] args) {
            int a=5,b=2,c=1;
            System.out.println(a+" "+b+" "+c);
            change(a,b,c);
            System.out.println(a+" "+b+" "+c);
            System.exit(0);        
        }    
        public static void change(int x,int y,int z) {
            x*=2;
            y*=2;
            z*=2;
        }
    }

    测试截图:

  • 相关阅读:
    20181223何家豪 Exp3-免杀原理
    实验一 密码引擎-3-电子钥匙功能测试 20181223何家豪
    Exp2-后门原理与实践 20181223何家豪
    实验四 Web服务器-socket编程
    Faster Rcnn训练自己的数据集过程大白话记录
    python线性数据结构
    越来越清晰的TFRecord处理图片的步骤
    更加清晰的TFRecord格式数据生成及读取
    生成TFRecord文件完整代码实例
    python 多进程处理图像,充分利用CPU
  • 原文地址:https://www.cnblogs.com/Lizhichengweidashen/p/13493147.html
Copyright © 2011-2022 走看看