步骤:
(1)流浪猫信息列表可以分为2个部分:顶部流浪猫属性和具体的数据。
(2)顶部流浪猫的属性值固定:昵称、性别、花色和出没地点可以直接打印。
(3)每只流浪猫的信息都不同,可以通过定义变量来保存:昵称(String类型(字符串类型))、性别(char类型(字符型))、出没地点(String类型)。
public class Main { public static <string> void main(String[] args) { // 打印顶部流浪猫属性 System.out.println("昵称\t性别\t花色\t出没地点"); // 定义流浪猫信息 String nickname1 = "小花"; char gender1 = '母'; String color1 = "白色"; String location1 = "图书馆"; String nickname2 = "小黑"; char gender2 = '公'; String color2 = "黑色"; String location2 = "校园教室"; String nickname3 = "小黄"; char gender3 = '公'; String color3 = "棕色"; String location3 = "校园食堂"; // 输出流浪猫信息 System.out.println(nickname1 + "\t" + gender1 + "\t" + color1 + "\t" + location1); System.out.println(nickname2 + "\t" + gender2 + "\t" + color2 + "\t" + location2); System.out.println(nickname3 + "\t" + gender3 + "\t" + color3 + "\t" + location3); } }
以上为本实验的实验代码,运行结果如下,