⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fillarray.java

📁 JAVA 2入门经典 练习答案
💻 JAVA
字号:
// Chapter 14 Exercise 1
/* 
  This is something of a trick question.
  You can use the static fill() method in the Arrays class to fill a char[]
  array with a given character. All you need to do to fill an array with some other
  value is to cast the value to type char and use the library method.
*/
import java.util.Arrays;
public class FillArray {
  public static void fill(char[] array, short value) {
    java.util.Arrays.fill(array, (char)value);
  }

  public static void main(String[] args) {
    char[] chars = new char[20];
    short value = 90;     // This is equivalent to 'Z'
    fill(chars, value);
    System.out.print("The array contains: ");
    for(int i = 0 ; i<chars.length ; i++)
      System.out.print(chars[i]);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -