日撸代码300行:第二天

代码来自闵老师”日撸Java三百行(01-10天,基本语法),原文链接:“https://blog.csdn.net/minfanphd/article/details/116933803
文章标题是根据原博客日程写的学习记录,真实的学习并没有严格按照时间。因工作原因,每天学习一点点,尽量坚持每天不间断的进行学习和总结。今天的代码如下:

package basic/*
 * ************************************************************
 * This is second code.
 * @author Wang X
 * ************************************************************
 */
public class BasicOperations {
       public static void main(String args[]) {
           int tempFirstInt,tempSecondInt,tempResultInt;
           double tempFirstDouble,tempSecondDouble,tempResultDouble;
  
           tempFirstInt = 15;
           tempSecondInt = 4;
  
           tempFirstDouble = 1.2;
           tempSecondDouble = 3.5;
  
           //Addition
           tempResultInt = tempFirstInt + tempSecondInt;
           tempResultDouble = tempFirstDouble +tempSecondDouble;
  
           System.out.println(""+tempFirstInt+" + "+tempSecondInt+""  + "=" + tempResultInt);
           System.out.println(""+tempFirstDouble+" + "+tempSecondDouble+" = " + tempResultDouble);
  
           //Subtraction
           tempResultInt = tempFirstInt - tempSecondInt;
           tempResultDouble = tempFirstDouble - tempSecondDouble;
  
           System.out.println("" + tempFirstInt + " - " + tempSecondInt + " = " + tempResultInt + "");
           System.out.println("" + tempFirstDouble + " - " + tempSecondDouble + " = " + tempResultDouble +"");
  
           //Multiplication
           tempResultInt = tempFirstInt * tempSecondInt;
           tempResultDouble = tempFirstDouble * tempSecondDouble;
  
           System.out.println("" + tempFirstInt + " * " + tempSecondInt + " = " + tempResultInt + "");
           System.out.println("" + tempFirstDouble + " * " + tempSecondDouble + " = " + tempResultDouble +"");
  
           //Division
           tempResultInt = tempFirstInt / tempSecondInt;
           tempResultDouble = tempFirstDouble / tempSecondDouble;
  
           System.out.println("" + tempFirstInt + " / " + tempSecondInt + " = " + tempResultInt + "");
           System.out.println("" + tempFirstDouble + " / " + tempSecondDouble + " = " + tempResultDouble +"");
  
           //Modulus
           tempResultInt = tempFirstInt % tempSecondInt;
  
           System.out.println("" + tempFirstInt + " % " + tempSecondInt + " = " + tempResultInt + "");
       }//of main
}//of class BasicOperations

今天主要对system.out.println()又有了进一步的理解。其中system是类,out是system类的一个静态数据成员,println是java.io.printstream里面的一个方法。所以System.out是调用了System类的静态数据成员out,System.out.println()又是该数据成员调用了println方法。
System.out.println()中的"+"就是用来拼接前后的字符串或者代码的。双引号里面的内容会直接输出到控制台,代表一个常量字符串。所有不带引号的,比如最后面的i,必须是计算机所能识别的值,可以是你已经定义过的参数,也可以是系统自己能直接获得的参数。
system.out.println()可以直接打印字符数组,但是没办法直接打印数值型数组。如下图:
日撸代码300行:第二天_第1张图片
日撸代码300行:第二天_第2张图片
原因解释搜了一篇博文,但是没有完全理解,先暂时记录下链接https://blog.51cto.com/sunyqlinux/115766

你可能感兴趣的:(eclipse,java)