Java 学习笔记 (六) Java 定义变量

这个问题来自于head first一书page68.

 package com.idea.study;

 public class Books {   //headfirst page68
String title; //为什么要写在这里?写在方法里就不行?
String author;
public static void main(String[] args){
Books[] myBooks = new Books[3];
int x=0;
myBooks[0] = new Books();
myBooks[1] = new Books();
myBooks[2] = new Books();
myBooks[0].title = "The Grapes of Java";
myBooks[1].title = "The Java Gatsby";
myBooks[2].title = "The Java Cookbook";
myBooks[0].author = "bob";
myBooks[1].author = "sue";
myBooks[2].author = "ian";
while(x<3){
System.out.print(myBooks[x].title);
System.out.print(" by ");
System.out.println(myBooks[x].author);
x=x+1;
} }
}
上一篇:电脑如何进入BIOS?在BIOS模式下USB的启动热键是什么?


下一篇:百度图表插件echart简单应用,简单配置一些要显示的样式及种类