zoukankan      html  css  js  c++  java
  • java step1:基础知识1

    1.String[] args

       args[i].charAt(j) : 表示这个表达式将从第i个命令行参数中抽出第j个字符。

    2.ArrayList对象

       ArrayList与数组相似,但ArrayList可以扩展为任意大小。  (在java.util包中)

       创建ArrayList:ArrayList table=new ArrayList();

       添加元素:table.add(...);

    3.计算大阶乘 20!是64位整数所能容纳的最大阶乘

        java.math.BigInteger类表示任意的大整数,BigInteger是对象而不是基本值,不能简单使用*操作符来完成BigInteger对象的相乘,应使用multiply()方法。

        e.g. for(int size=table.size();size<=x;size++)

      {

                 BigInteger lastfact=(BigInteger)table.get(size-1);

          BigInteger nextfact=lastfact.multiply(BigInteger.valueof(size));

         table.add(nextfact);
      }

    4.Integer.parseInt():将制定的一个字符串转换为一个数

    5.BufferedReader对象的readLine()方法实现从键盘读取用户输入的技术

      BufferedReader in=new BUfferedReader(new InputStreamReader(System.in));

      for(;;)

      {

        System.out.print(">");

        String line=in.readLine();

        if((line==null)||line.equals("quit")) break;

      }

    6.java中表示字符串的String类,是不可变的。即未提供任何允许修改字符串内容的方法。对字符串操作的方法返回一个新字符串,而非原字符串修改后的副本。原地操作一个字符串,需使用StringBuffer对象。

      String line=in.readLine();

      StringBuffer buf=new StringBuffer(line);

          for(int i=0;i<buf.length;i++)

               buf.setCharAt(i,buf.charAt(i)-1);

        

  • 相关阅读:
    隐藏NGINX服务器名称 和版本号
    salt-grains
    格式化输出文本的方法
    递归例子
    yield 生成器例子
    Python基础之函数
    Python基础之面向对象
    Python基础之模块2
    Python基础之字符编码
    Python基础之文件操作
  • 原文地址:https://www.cnblogs.com/shaoneng111/p/4078416.html
Copyright © 2011-2022 走看看