0
スタックから要素を印刷すると、各要素間に大量の空白または空白があります。スタックから印刷するときに空白をスキップする方法
可能であれば、もっと近くにそれらを一緒に印刷したいと思っています。
スタックの要素をその位置に保持し、現在取り込んでいるもの以外のすべての文字を無効にします。
import java.io.*;
public class File
{
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new
FileReader("input.txt"));
String str;
while((str = in.readLine()) != null){
System.out.println("I just read: "+ str);
StackOfStrings[] ss = new StackOfStrings[35];
for(int i=0; i <= 9; i++){
ss[i] = new StackOfStrings();
}
if(str.charAt(4) == 'm') {
ss[0].push("m");
}
}
in.close();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
これはインタフェース
public class StackOfStrings implements StackInterface {
private Node first; //top
private int n;
public StackOfStrings(){
first = null;
n=0;
}
public boolean isEmpty() {
return first == null;
}
public int size() {
return n;
}
public void push(String item)
{
Node x = new Node();
x.item = item;
x.next = first;
first = x;
}
public String pop() {
String val = first.item;
first = first.next;
n--;
return val;
}
private class Node {
String item;
Node next;
}
public String toString()
{
String s="";
Node t = first;
while(t != null) {
s += t.item + " ";
t= t.next;
}
return s;
}
}
は確かにあなたを – notyou
@notyouを@Overrideすることを忘れないでください。正しいです –
あなたの助けに感謝、私は今toStringメソッドがある – kingerick