Как получилось, когда я положил // private String namespace = "### Name:" + name + "###"; а system.out.println (namespace) выходит null?
Предполагается, что я создаю программу создания тегов, но я застрял в том, как выстроить # справа.
/*################################################
### ANNUAL CONFERENCE ###
############################################### #
###Name:Simon ###
### ###
############################################### #
###Organization:NBA ###
### ###
################################################*/
Как выстроить их в соответствие с любым заданным именем?
Я полагаю, чтобы установить имя, установить организацию, распечатать тег с именем и организацией, очистить имя и организацию и напечатать пустой тег.
---------------- ОБНОВЛЕНИЕ 4:09 --------------------------- -
Я просто собираюсь смоделировать свой код после этого:
public class Divers {
public static void main(String args[]){
String format = "|%1$-10s|%2$-10s|%3$-20s|\n";
System.out.format(format, "FirstName", "Init.", "LastName");
System.out.format(format, "Real", "", "Gagnon");
System.out.format(format, "John", "D", "Doe");
String ex[] = { "John", "F.", "Kennedy" };
System.out.format(String.format(format, (Object[])ex));
}
}
но кто-то может показать мне, как я могу сделать это по-другому? только для учебных целей
public class AddressBookTester {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
TagMaker test = new TagMaker("Simon", "NBA");
test.printlL();
}
}
public class TagMaker {
private String name;
private String organization;
private String l = "################################################";
private String annual= "### ANNUAL CONFERENCE ###";
//private String namespace = "###Name:"+name+" ###";
private String l2= "### ###";
//private String organizationspace= "###Organization:"+organization+"###";
TagMaker (){
}
TagMaker (String tempName, String tempOrg){
name = tempName;
organization = tempOrg;
}
void setname(String tempName){
name = tempName;
}
String getname(){
return name;
}
void setorganization(String tempOrg)
{
organization = tempOrg;
}
String getorganization(){
return organization;
}
void printlL(){
System.out.println(l);
System.out.println(annual);
System.out.println(l);
System.out.println("###Name:"+name+" ###");
System.out.println(l2);
System.out.println(l);
System.out.println("###Organization:"+organization+" ###");
System.out.println(l2);
System.out.println(l);
}
}