import java.io.*;
class Main0
{
public static void main(String args[])
{
String onoma, epitheto, key01;
short AriMit, EtosEis, AM, key02;
int i, pos;
Foititis pinakas[] = new Foititis(3);
for (i = 0; i < pinakas.length; i++)
{
System.out.println("Ola ta stoixeia na einai taksinomimena symfwna me ton Arithmo Mitroou." + "\n" + "Dwste Onoma.");
do
{
onoma = FUserInput.getString();
if (onoma == "x")
System.out.println("Mh egkyrh timh. Epanalagete");
} while (onoma == "x");
System.out.println("Dwste Epitheto.");
do
{
epitheto = FUserInput.getString();
if (epitheto == "x")
System.out.println("Mh egkyrh timh. Epanalagete");
} while (epitheto == "x");
System.out.println("Dwste Arithmo Mitrwou.");
do
{
AriMit = FUserInput.getshort();
if (AriMit == -1)
System.out.println("Mh egkyrh timh. Epanalagete");
} while (AriMit == -1);
System.out.println("Dwste Etos Eisagwghs.");
do
{
EtosEis = FUserInput.getshort();
if (EtosEis == -1)
System.out.println("Mh egkyrh timh. Epanalagete");
} while (EtosEis == -1);
pinakas[i] = new Foititis(onoma, epitheto, AriMit, EtosEis);
}
pos = 1;
System.out.println(Foititis.toString(pos, pinakas));
}
}
class Foititis
{
private String onoma, epitheto;
private short AriMit, EtosEis;
public Foititis (String on, String ep, short AM, short EE)
{
onoma = on;
epitheto = ep;
AriMit = AM;
EtosEis = EE;
}
public String getEpwnymo() //alles klaseis
{
return epitheto;
}
public String toString(int j, Foititis b[])
{
String emf;
emf = b[j].onoma;
}
}
class FUserInput
/*dedomenwn kateli3a na xrisimopoihsw thn "FUserInput" gia ola ta dedomena, anti na kanw "catch" to "exception" gia kathe scanner ksexwrista, kathws eixa skopo na xrisimopoihsw mono scanner)*/
{
static String getString()
{
String line;
InputStreamReader eisodosDouble = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(eisodosDouble);
try
{
line = br.readLine();
return line;
}
catch(Exception e)
{
return "x";
}
}
static short getshort()
{
String line;
InputStreamReader eisodosDouble = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(eisodosDouble);
try
{
line = br.readLine();
short i = Short.parseShort(line);
return i;
}
catch(Exception e)
{
return -1;
}
}
}
这不是任何重复,我不是在询问我的字符串方程式,而是关于我想要使用的toString方法!!!!
所以我有这个代码...它所做的只是创建一个Foititis
类型的对象数组,名为pinakas
并具有四个属性。如果您查看名为Foititis
的类,您会注意到toString
方法,我想要做的就是使用toString
方法在屏幕上显示某些内容(在此示例中,它已简化到array-object的onoma
属性。请注意,我还想发送我想要看到的数组的某个位置(pos - &gt; j),在这个例子中,位置是固定的(设置为1)但在实际代码中它不会。 / p>
我尝试编译它并且我得到这两个错误,第二个可能是合理的,因为我没有以正确的方式编写代码,但是第一个呢?我再次做了同样的事情,我没有问题(创建一个对象数组)。
答案 0 :(得分:1)
您正在尝试声明一个数组,因此它应该是:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building cms 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ cms ---
[INFO] Deleting /home/korbeldaniel/git/cms/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cms ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 18 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ cms ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 117 source files to /home/korbeldaniel/git/cms/target/cms/WEB-INF/classes
[INFO] /home/korbeldaniel/git/cms/src/main/java/pl/korbeldaniel/cms/server/entity/GenericEntity.java: Some input files use unchecked or unsafe operations.
[INFO] /home/korbeldaniel/git/cms/src/main/java/pl/korbeldaniel/cms/server/entity/GenericEntity.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ cms ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/korbeldaniel/git/cms/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ cms ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ cms ---
[INFO] No tests to run.
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:compile (default) @ cms ---
[INFO] auto discovered modules [pl.korbeldaniel.cms.cms]
[INFO] Compiling module pl.korbeldaniel.cms.cms
[INFO] Ignored 1 unit with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO] Computing all possible rebind results for 'pl.korbeldaniel.cms.client.service.LoginService'
[INFO] Rebinding pl.korbeldaniel.cms.client.service.LoginService
[INFO] Invoking generator org.fusesource.restygwt.rebind.RestServiceGenerator
[INFO] Generating: pl.korbeldaniel.cms.client.service.LoginService_Generated_RestServiceProxy_
[INFO] classname to resolve: org.fusesource.restygwt.rebind.ModelChangeAnnotationResolver
[INFO] add annotationresolver: org.fusesource.restygwt.rebind.ModelChangeAnnotationResolver
[ERROR] log4j:WARN No appenders could be found for logger (org.hibernate.validator.util.Version).
[ERROR] log4j:WARN Please initialize the log4j system properly.
[ERROR] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[INFO] Compiling 1 permutation
[INFO] Compiling permutation 0...
[INFO] Compile of permutations succeeded
[INFO] Compilation succeeded -- 16,905s
[INFO] Linking into /home/korbeldaniel/git/cms/target/cms/cms
[INFO] Invoking Linker Verify the availability of a more recent version of GWTP.
[INFO] Checking version information for gwtp-mvp-client
[INFO] [WARN] ------------------------------------------------------------
[INFO] [WARN] A new version of gwtp-mvp-client is available!
[INFO] [WARN] Your version: 1.5
[INFO] [WARN] Latest version: 1.5.2
[INFO] [WARN] See http://search.maven.org/#artifactdetails|com.gwtplatform|gwtp-mvp-client|1.5.2|jar
[INFO] [WARN] ------------------------------------------------------------
[INFO] Link succeeded
[INFO] Linking succeeded -- 0,745s
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ cms ---
[INFO] Packaging webapp
[INFO] Assembling webapp [cms] in [/home/korbeldaniel/git/cms/target/cms]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/korbeldaniel/git/cms/src/main/webapp]
[INFO] Webapp assembled in [111 msecs]
[INFO] Building war: /home/korbeldaniel/git/cms/target/cms.war
[INFO]
[INFO] --- gwt-maven-plugin:2.7.0:test (default) @ cms ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ cms ---
[INFO] Installing /home/korbeldaniel/git/cms/target/cms.war to /home/korbeldaniel/.m2/repository/pl/korbeldaniel/cms/cms/0.0.1-SNAPSHOT/cms-0.0.1-SNAPSHOT.war
[INFO] Installing /home/korbeldaniel/git/cms/pom.xml to /home/korbeldaniel/.m2/repository/pl/korbeldaniel/cms/cms/0.0.1-SNAPSHOT/cms-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.520 s
[INFO] Finished at: 2016-03-11T11:09:11+01:00
[INFO] Final Memory: 37M/427M
[INFO] ------------------------------------------------------------------------