我正在尝试在.txt文档中以ASCII-art打印命令行参数。 然而,我创建的addChar方法,用于向将要打印的单词添加字符,不会做任何事情。我添加了一个System.out.println()来检查它是否到达方法的开头,但它没有。
以下是代码的相关部分:
import java.io.*;
public class Test {
private static String[] savedArgs;
public static String[] getArgs() {
return savedArgs;
}
public static void main(String[] args) {
savedArgs = args;
AsciiString A = new AsciiString();
print(A.toString(),true,"BESTANDSNAAM.txt");
}
public static void print(String string, boolean naarBestand, String bestandsnaam)
{
if (naarBestand){
try {
FileWriter bestand = new FileWriter(bestandsnaam);
BufferedWriter out = new BufferedWriter(bestand);
out.write(string);
out.close();
}
catch(IOException exception){
System.out.println("Kan niet wegschrijven naar bestand "+bestandsnaam);
}
}
else {
System.out.println(string);
}
}
}
class AsciiString{
String cla[] = Test.getArgs();
String woordString = "";
String cla1 = cla[0];
int x = cla1.length();
char args[] = new char[x];
String woord[] = new String[x];
public AsciiString(){
for(int i=0; i<x; i++){
int j=0;
args[j] = cla1.charAt(i);
j++;
}
}
public void addChar(AsciiChar letter){
System.out.println("gebeurt dit wel?");
for(int i=0; i<woord.length; i++){
AsciiChar Letter = new AsciiChar(args[i]);
woord[i] += Letter;
}
}
public void addCharJoin(AsciiChar letter){
}
public String toString(){
System.out.println("en dit?");
for (int i=0; i<woord.length; i++){
woordString += woord[i];
woordString += "\r\n";
}
return woordString;
}
}
class AsciiChar {
String letterArray[][] = new String[6][13];
String letterString = "";
public AsciiChar(char letter){
switch(letter){
case 'A':
在这之间是ASCII艺术字母的字符串值(长达几千行并且没有趣味)。我添加了最后一行,所以你知道我的意思(letterArray [5] [12]等。)。
letterArray[5][12] = " ";
break;
default:
System.out.println("Input not recognized, please only give capitol letters as input.");
}
}
public String toString(){
for (int i=0; i<letterArray.length; i++){
for (int j=0; j<letterArray[i].length; j++){
letterString += letterArray[i][j];
}
letterString += "\r\n";
}
return letterString;
}
}
答案 0 :(得分:1)
您需要在addChar()
上调用AsciiString's Instance
方法。你从来没有调用它。我不知道它适合你的代码。
public static void main(String[] args) {
savedArgs = args;
AsciiString A = new AsciiString();
print(A.toString(),true,"BESTANDSNAAM.txt");
A.addChar(yourargument);
}