Created
April 26, 2012 05:58
-
-
Save hatone/2496410 to your computer and use it in GitHub Desktop.
forループまわり
This file contains hidden or 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
| public class Diamond { | |
| public static void main (String[] args) { | |
| for (int j = 0; j < 8; j++) { | |
| for (int i = 7; i-j>0; i-- ) { | |
| System.out.print(" "); | |
| } | |
| for (int i = 1; i<j*2; i++){ | |
| System.out.print("*"); | |
| } | |
| System.out.println(""); | |
| } | |
| for (int j = 1; j < 7; j++) { | |
| for (int i = 0; i < j; i++) { | |
| System.out.print(" "); | |
| } | |
| for (int i = 13; i - j*2 > 0 ; i--){ | |
| System.out.print("*"); | |
| } | |
| System.out.println(""); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| 演習1: | |
| Triangle.javaというファイルを作成し、以下の実行結果が表示されるプログラムをfor文を使用して作成しなさい。 | |
| ---- 実行結果 ---- | |
| * | |
| ** | |
| *** | |
| **** | |
| ***** | |
| ****** | |
| ******* | |
| ******** | |
| ********* | |
| ********** | |
| ********* | |
| ******** | |
| ******* | |
| ****** | |
| ***** | |
| **** | |
| *** | |
| ** | |
| * | |
| ---- | |
| 演習2: | |
| Diamond.javaというファイルを作成し、以下の実行結果が表示されるプログラムをfor文を使用して作成しなさい。 | |
| ---- 実行結果 ---- | |
| * | |
| *** | |
| ***** | |
| ******* | |
| ********* | |
| *********** | |
| ************* | |
| *********** | |
| ********* | |
| ******* | |
| ***** | |
| *** | |
| * | |
| ---- | |
| 演習3: | |
| Mottled.javaというファイルを作成し、以下の実行結果が表示されるプログラムをfor文を使用して作成しなさい。 | |
| ---- 実行結果 ---- | |
| * * * * * * * | |
| *** *** *** *** *** *** *** | |
| ***** ***** ***** ***** ***** ***** ***** | |
| ******* ******* ******* ******* ******* ******* ******* | |
| ***** ***** ***** ***** ***** ***** ***** | |
| *** *** *** *** *** *** *** | |
| * * * * * * * | |
| * * * * * * * | |
| *** *** *** *** *** *** *** | |
| ***** ***** ***** ***** ***** ***** ***** | |
| ******* ******* ******* ******* ******* ******* ******* | |
| ***** ***** ***** ***** ***** ***** ***** | |
| *** *** *** *** *** *** *** | |
| * * * * * * * | |
| * * * * * * * | |
| *** *** *** *** *** *** *** | |
| ***** ***** ***** ***** ***** ***** ***** | |
| ******* ******* ******* ******* ******* ******* ******* | |
| ***** ***** ***** ***** ***** ***** ***** | |
| *** *** *** *** *** *** *** | |
| * * * * * * * | |
| ---- |
This file contains hidden or 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
| public class Triangle{ | |
| public static void main(String[] args) { | |
| for(int i = 0; i<5; i++) { | |
| for(int j = 0; j < i; j++) { | |
| System.out.print("a"); | |
| } | |
| System.out.println(""); | |
| } | |
| for(int i = 5; i>0; i--) { | |
| for(int j = 0; j < i; j++) { | |
| System.out.print("b"); | |
| } | |
| System.out.println(""); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment