Created
November 29, 2017 14:14
-
-
Save SRsawaguchi/1cc84367df0e164c79f760e0b3825e45 to your computer and use it in GitHub Desktop.
三角形を出力するJava
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
public class Main { | |
//初めから1000このアスタリスク用意!!( ´∀` ) | |
//php -r "echo str_repeat('*', 1000);" | |
public static String ASTA = "****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************"; | |
public static void main(String[] args) throws Exception { | |
// Your code here! | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String line = br.readLine(); | |
Main.printTriangle(Integer.parseInt(line), 1); | |
} | |
public static void printTriangle(int max, int n){ | |
if(n >= max){ | |
System.out.println(ASTA.substring(0, max)); | |
}else{ | |
System.out.println(ASTA.substring(0, n)); | |
printTriangle(max, n + 1); | |
System.out.println(ASTA.substring(0, n)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment