Skip to content

Instantly share code, notes, and snippets.

@SRsawaguchi
Created November 29, 2017 14:14
Show Gist options
  • Save SRsawaguchi/1cc84367df0e164c79f760e0b3825e45 to your computer and use it in GitHub Desktop.
Save SRsawaguchi/1cc84367df0e164c79f760e0b3825e45 to your computer and use it in GitHub Desktop.
三角形を出力するJava
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