- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何打印/引用第 7 号人员?谢谢!
我已经尝试了多种方法,但是我无法引用第 7 个人。我是数组新手,明天到期,所以任何帮助都会很棒。我看了 youtube 上的一些教程,但我就是不明白出了什么问题?重新定义数组的方式与我看到的示例不同。
import java.text.*; // to use Decimal Format
public class TwoD_ArrayDriver
{
public static void main(String[] args)
{
DecimalFormat myFormat;
// to get 2 decimals every time
myFormat = new DecimalFormat("#.00");
Person p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21;
p1 = new Person("Abby", "Arthur"); p2 = new Person("Bubba","Brown"); p3 = new Person("Chuckie", "Cheese"); p4 = new Person("Don", "Drysdale"); p5 = new Person("Ernie","Eastwood");
p6 = new Person("Flo", "Fauntroy"); p7 = new Person("Gabby", "Giffords"); p8 = new Person("Hank","Hoover"); p9 = new Person("Indy", "Imhauf"); p10 = new Person("Jim","Jones");
p11 = new Person("Ken", "Koopman"); p12 = new Person("Larry", "Lancelot"); p13 = new Person("Michael", "Moore" ); p14 = new Person("Nina","Nonesuch"); p15 = new Person("Oscar","OToole");
p16 = new Person("Pat","Pompous"); p17 = new Person("Quincy","Quinton"); p18 = new Person("Ralph","Rancid"); p19 = new Person("Steven","Simpson"); p20 = new Person("Tim","Tinker");
p21 = new Person("Uncle","Usher");
Person[] allPersons = {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21};
Person[] mondayAppts = {p1, p2, p3, p4, p5};
Person[] tuesdayAppts = {p6, p7, p8};
Person[] wednesdayAppts = {p9, p10, p11, p12};
Person[] thursdayAppts = {p13, p14, p15, p16, p17};
Person[] fridayAppts = {p18, p19, p20, p21};
//Task #1 Print the id, first name, and last name of Person #7, using tuesdayAppts
int intToPrint = 0;
String fNameToPrint = "unknown";
String lNameToPrint = "unknown";
System.out.println("Person #7 "+intToPrint+" "+fNameToPrint+" "+lNameToPrint);
最佳答案
由于您尝试通过 tuesdayAppts
作为 Person[] tuesdayAppts = {p6, p7, p8};
访问变量 p7
,您应该执行 tuesdayAppts[1]
,因为它位于数组的第二个位置。
Person #2 BBB bbb
)class Person {
private static int idGen = 0;
private int id;
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.id = ++Person.idGen;
}
public String toString() {
return "Person #" + this.id + " " + this.firstName + " " + this.lastName;
}
}
class Example {
public static void main(String[] args) {
Person a, b, c;
a = new Person("AAA", "aaa");
b = new Person("BBB", "bbb");
c = new Person("CCC", "ccc");
Person[] personArray = {a, b, c};
System.out.println(personArray[1]);
}
}
关于java - 如何打印/引用第 7 号人物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46678852/
此代码的目标是找出所需的删除内容使字符串之间没有相同的字符。 ababa = 0 abaaab = 2 and aaaa = 3 var input ="abababaaaabaaab"; var s
我需要一些帮助。我必须从文件中读取数据并将其存储到 Oracle 数据库中。当数据中出现“à”或“À”等字符时,我会遇到麻烦。例如,“à”被读取并变成“à”进入我的应用程序,因此,当我尝试将数据保存到
我用! @ # $ 在我的 MySQL 用户的密码中 但是当我在密码中使用这些字符时,PDO 无法连接到 MySQL 服务器 $servername = "localhost"; $username
我需要点击鼠标按钮才能在两个轴上旋转图形。当您释放鼠标按钮时,图形将旋转到原始位置。轻微旋转时,一切都会按预期进行,但大幅旋转 ( 0) { if (sumRotate -D
我有 this xml file 我正在尝试访问PHP中的标记permission中的yt:accessControl属性值 echo (string)$xmlyt->entry->children(
我正在尝试从我的 GitHub 在 Netlify 上部署我的网站。 但是我坚持以下错误: 11:37:19 AM: failed during stage 'deploying site': Inv
我是一名优秀的程序员,十分优秀!