【发布时间】:2013-09-22 01:20:10
【问题描述】:
我在一个项目中有三个文件,我似乎无法在我的主类打印中打印 println 语句!帮忙?
第一个文件:
package chapter2;
public class UseStringLog
{
public static void main(String[] args)
{
StringLogInterface log;
log = new ArrayStringLog("Example Use");
log.insert("Elvis");
log.insert("King Louis XII");
log.insert("Captain Kirk");
System.out.println(log);
System.out.println("The size of the log is " + log.size());
System.out.println("Elvis is in the log: " + log.contains("Elvis"));
System.out.println("Santa is in the log: " + log.contains("Santa"));
}
}
第二个文件:
package chapter2;
public interface StringLogInterface
{
void insert(String element);
boolean isFull();
int size();
boolean contains(String element);
void clear();
String getName();
String toString();
}
第三个文件:
package chapter2;
public class ArrayStringLog implements StringLogInterface
{
protected String name;
protected String[] log;
protected int lastIndex = -1;
public ArrayStringLog(String name, int maxSize)
{
log = new String[maxSize];
this.name = name;
}
public ArrayStringLog(String name)
{
log = new String[100];
this.name = name;
}
public void insert(String element)
{
lastIndex++;
log[lastIndex] = element;
}
public boolean isFull()
{
if (lastIndex == (log.length - 1))
return true;
else
return false;
}
public int size()
{
return (lastIndex + 1);
}
public boolean contains(String element)
{
int location = 0;
while (location <= lastIndex)
{
if (element.equalsIgnoreCase(log[location])) // if they match
return true;
else
location++;
}
return false;
}
public void clear()
{
for (int i = 0; i <= lastIndex; i++)
log[i] = null;
lastIndex = -1;
}
public String getName()
{
return name;
}
public String toString()
{
String logString = "Log: " + name + "\n\n";
for (int i = 0; i <= lastIndex; i++)
logString = logString + (i+1) + ". " + log[i] + "\n";
return logString;
}
}
我运行每一个都成功构建,但没有输出!
【问题讨论】:
-
你如何运行你的程序?你得到的输出是什么?
-
您根本没有得到 any 输出吗?甚至没有硬编码的字符串?另外,你在哪里运行这个?蚀?命令行?另一个 IDE?
-
我使用 NetBeans。我运行它,我得到的只是构建成功。
-
@KTF 对我来说它在Netbeans too 上工作得很好,你一定错过了什么......
标签: java arrays string logging output