ฉันกำลังทำอะไรออกกำลังทำงานของจาวาตั้งโปรแกรมแน่นอนว่า,คำถามก็เป็นงั้น:
เขียนเป็นวิธีการเรียก printTree นั่นแสดงผลจะเป็นแฟ้มเป็นสามเหลี่ยมของ asterisks อ้างอิงจากความสูงค่าอผ่านไปขั้นตอนการรักษาที่เราให้เธอ ทดสอบวิธีการนี้อยู่ในหลักวิธีการ.
- E. g. สามเหลี่ยมของความสูงของ 3 ควรจะส่งออกไปเป็นแฟ้มเรียก file14:
ฉันแค่ไม่แน่ใจว่าจะเขียนไม่มีประโยชน์ที่จะกลับแฟ้มที่ผมเคยทำที่หลักวิธีการ. ฉันอยากจะย่องกำลังนำเข้าขออื่นจาวา.บ io วิธีการของนอกเหนือจาก FileWriter แต่มีความช่วยเหลือซาบซึ้งขอบคุณนะ
import java.io.PrintWriter;
public class OutputToFile14 {
public static void main(String[] args) throws Exception{
//Creating PrintWriter
PrintWriter output = new PrintWriter("file14.txt");
//writing method output to file
output.write(printTree(4));
//saving file
output.close();
}
public static void printTree (int height) throws IOException{
for (int i = 0; i < height; i++) {
for (int j = 0; j < height; j++) {
if (j < i) {
System.out.print("*");
}
}
System.out.println();
}
}
}