Last active
March 8, 2019 13:33
-
-
Save Terng/666920ffe6a8339e40144187e7ece8df to your computer and use it in GitHub Desktop.
lab 3 (loop แสดงตัว & และเว้นวรรค กับ รูปแสดงแถว)
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
package com.terng; | |
public class Main { | |
public static void main(String[] args) { | |
for (int i=0; i<=3;i++) | |
{ | |
System.out.println(); | |
for (int j=0;j<=9;j++) | |
{ | |
System.out.print("&"); | |
} | |
if (i==2) | |
{ | |
System.out.print("\n"); | |
} | |
} | |
} | |
} | |
///////////////////////////////////// | |
import java.util.Scanner; | |
public class Loop2 | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.print("Please input the num for loop : "); | |
Scanner n = new Scanner(System.in); | |
int num = n.nextInt(); | |
System.out.print("input : " +num+"\n"); | |
int counter = num; | |
for (int i = 1; i<=num; i++ ) | |
{ | |
System.out.println(); | |
for (int j = counter; j >=1;j--) | |
{ | |
System.out.print(j + " "); | |
} | |
counter--; | |
} | |
} | |
} | |
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
package com.terng; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]){ | |
System.out.print("Please input the num for loop : "); | |
Scanner n = new Scanner(System.in); | |
int num = n.nextInt(); | |
System.out.print("input : " +num+"\n"); | |
int counter = num; | |
for(int i=counter; i>0 ;i--){ | |
for(int j=0; j < i; j++){ | |
System.out.print(j+1 +" "); | |
} | |
System.out.println(""); | |
} | |
} | |
} | |
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
package com.terng; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]){ | |
System.out.print("Please input the num for loop : "); | |
Scanner n = new Scanner(System.in); | |
int num = n.nextInt(); | |
System.out.print("input : " +num+"\n"); | |
int counter = num; | |
for(int i=counter; i>=1 ;i--){ | |
for(int j=i; j <= counter; j++){ | |
System.out.print(j +" "); | |
} | |
System.out.println(""); | |
} | |
} | |
} | |
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
package com.terng; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]){ | |
System.out.print("Please input the num for loop : "); | |
Scanner n = new Scanner(System.in); | |
int num = n.nextInt(); | |
System.out.print("input : " +num+"\n"); | |
int counter = num; | |
for(int i=1; i<=counter ;i++){ | |
for(int j=i; j >= 1; j--){ | |
System.out.print(j +" "); | |
} | |
System.out.println(""); | |
} | |
} | |
} | |
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
package com.terng; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]){ | |
System.out.print("Please input the num for loop : "); | |
Scanner n = new Scanner(System.in); | |
int num = n.nextInt(); | |
System.out.print("input : " +num+"\n"); | |
int counter = num; | |
for(int i=1; i<=counter ;i++){ | |
for(int j=1; j <= i; j++){ | |
System.out.print(i +" "); | |
} | |
System.out.println(); | |
} | |
} | |
} | |
เพิ่มเติมลองเข้าไปดูเว็บนี้
https://codeography.wordpress.com/2016/08/06/1-21-321-4321-54321/
แต่เป็นภาษา C ให้ดู for อย่างเดียวแล้วเอามาเปลี่ยน
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ผลลัพธ์อันที่1
ผลลัพธ์อันที่ 2