使用for循环的Java ASCII艺术

时间:2017-09-25 17:34:55

标签: java loops

我完全陷入了这个java循环ASCII问题。

https://imgur.com/a/CowB3

我想出了如何做顶线,但我被困在身上。我不知道在嵌套for循环中放入什么以绘制反斜杠。任何帮助将不胜感激。这是我的代码:

    public static void SlashFigure(int size) {  
    System.out.println();  // line break  

    for(int i = 1; i <= (size * 4 - 2); i++) {       // draw top line  
        System.out.print("!");  
    }


    for(int i = 1; i <= size - 1; i++) {            // draw body  

        for(int j = 1; j <=  ; i++){               // draw backslashes 
            System.out.println("\\");  
        }  
    }    

1 个答案:

答案 0 :(得分:0)

查看以下内容是否有帮助。如果您不理解某个部分如何在以下代码中工作,请告诉我。

import sys, time, logging, io, re, os

from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage

def convert_pdf_to_txt(path):
    rsrcmgr = PDFResourceManager()
    retstr = io.StringIO()
    codec = 'utf-8'
    laparams = LAParams()
    device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
    fp = open(path, 'rb')
    interpreter = PDFPageInterpreter(rsrcmgr, device)
    password = ""
    maxpages = 0
    caching = True
    pagenos = set()

    for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages,
                                  password=password,
                                  caching=caching,
                                  check_extractable=True):
        interpreter.process_page(page)

    text = retstr.getvalue()

    inv_num = re.findall("(\d{5})", text)[1]
    inv_name = text.split('\n', 1)[0]
    new_name = inv_num + " " + inv_name

    fp.close()
    device.close()
    retstr.close()
    return new_name

def renameFileToPDFTitle(path, fileName):
    fullName = os.path.join(path, fileName)
    basename, extension = os.path.splitext(fileName)

    newName = convert_pdf_to_txt(fullName)  + extension
    newFullName = os.path.join(path, newName) 
    os.rename(fullName, newFullName)

class Event(LoggingEventHandler):
    def dispatch(self, event):
        for fileName in os.listdir(path):
        # Rename only pdf files
            fullName = os.path.join(path, fileName)
            if (not os.path.isfile(fullName) or fileName[-4:] != '.pdf'):
                continue
            renameFileToPDFTitle(path, fileName)

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = Event()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()