zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVA开发学习:StringBuffer、数组

    public class Test{
      public static void main(String args[]){
        StringBuffer sBuffer = new StringBuffer("菜鸟教程官网:");
        sBuffer.append("www");
        sBuffer.append(".runoob");
        sBuffer.append(".com");
        System.out.println(sBuffer);  
      }
    }
    public class TestArray {
       public static void main(String[] args) {
          // 数组大小
          int size = 10;
          // 定义数组
          double[] myList = new double[size];
          myList[0] = 5.6;
          myList[1] = 4.5;
          myList[2] = 3.3;
          myList[3] = 13.2;
          myList[4] = 4.0;
          myList[5] = 34.33;
          myList[6] = 34.0;
          myList[7] = 45.45;
          myList[8] = 99.993;
          myList[9] = 11123;
          // 计算所有元素的总和
          double total = 0;
          for (int i = 0; i < size; i++) {
             total += myList[i];
          }
          System.out.println("总和为: " + total);
       }
    }
    public class TestArray {
       public static void main(String[] args) {
          double[] myList = {1.9, 2.9, 3.4, 3.5};
     
          // 打印所有数组元素
          for (int i = 0; i < myList.length; i++) {
             System.out.println(myList[i] + " ");
          }
          // 计算所有元素的总和
          double total = 0;
          for (int i = 0; i < myList.length; i++) {
             total += myList[i];
          }
          System.out.println("Total is " + total);
          // 查找最大元素
          double max = myList[0];
          for (int i = 1; i < myList.length; i++) {
             if (myList[i] > max) max = myList[i];
          }
          System.out.println("Max is " + max);
       }
    }
    public class TestArray {
       public static void main(String[] args) {
          double[] myList = {1.9, 2.9, 3.4, 3.5};
     
          // 打印所有数组元素
          for (double element: myList) {
             System.out.println(element);
          }
       }
    }
    public static void printArray(int[] array) {
      for (int i = 0; i < array.length; i++) {
        System.out.print(array[i] + " ");
      }
    }
    public static int[] reverse(int[] list) {
      int[] result = new int[list.length];
     
      for (int i = 0, j = result.length - 1; i < list.length; i++, j--) {
        result[j] = list[i];
      }
      return result;
    }
    String s[][] = new String[2][];
    s[0] = new String[2];
    s[1] = new String[3];
    s[0][0] = new String("Good");
    s[0][1] = new String("Luck");
    s[1][0] = new String("to");
    s[1][1] = new String("you");
    s[1][2] = new String("!");
  • 相关阅读:
    JavaScript 基础知识 4
    JavaScript 基础知识 5 函数
    JavaScript 基础知识 3
    JavaScript 基础知识 2
    JavaScript 基础知识 1
    JavaScript 一
    HTML <a>等元素
    HTML CSS
    HTML <head> 元素
    HTML <meta> 标签
  • 原文地址:https://www.cnblogs.com/tszr/p/10960290.html
Copyright © 2011-2022 走看看