Computer Programming

  • Uploaded by: Bank
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Computer Programming as PDF for free.

More details

  • Words: 407
  • Pages: 4
MR. MAMPAN SANGSA 50052535 วิชา Computer Programming

1) public class TestIfElse { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new TestIfElse().calGrade(72); System.out.println(); new TestIfElse().calGrade(49); } public void calGrade(int points) { if (points > 50) { System.out.println("Your points more than 50"); System.out.println("Not Fail"); } else { System.out.println("Your points less than 50"); System.out.println(" Fail !!!"); } System.out.println("End calGrade"); } }

ผลลัพธ์ของโปรแกรม Your points more than 50 Not Fail End calGrade Your points less than 50 Fail !!! End calGrade

2) public class TestMultiDimesionArray { /** * @param args */ public static void main(String[] args) {

int int int for

}

number[][] = new int[10][]; count = 1; num = 1; (int i = 0; i < 10; i++) { number[i] = new int[count++]; for (int j = 0; j <= i; j++) { number[i][j] = num++; System.out.println(number[i][j] + "\t"); } System.out.println();

} }

ผลลัพธ์ของโปรแกรม 1 2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

3) public class TestArray { /** * @param args */ public static void main(String[] args) { char s[]; s= new char[26];//สร้างอาร์เรย์ของชนิ ดข้อมูล charขนาด26ช่อง

for (int i=0; i<s.length; i++){/*s.length ใช้หาขนาดอาร์เรย์s*/ s[i]=(char)('A'+i);/*กำาหนดค่าอักษรให้แต่ละช่องของอาร์เรย์s*/

} for (int i=0; i<s.length; i++){ System.out.print(s[i]+"\t");/*พิมพ์ของค่าอาร์เรย์ออกมาที่ละช่อง*/

} } }

ผลลัพธ์ของโปรแกรม A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

4) public class TestConcatString { /** * @param args */ public static void main(String[] args) { String msg1="Hello!"; String msg2="Every body"; String name1="My name is Sangsa."; String name2= "I come from Cambodia."; String name3="I'm study at Burapha University."; System.out.println(msg1); System.out.println(msg2); System.out.println(name1); System.out.println(name2); System.out.println(name3); } }

ผลลัพธ์ของโปรแกรม Hello! Every body My name is Sangsa. I come from Cambodia. I'm study at Burapha University.

5) public class TestGrade {

/** * @param args */ public static void main(String[] args) { new TestGrade().calGrade(72); new TestGrade().calGrade(49); new TestGrade().calGrade(80); new TestGrade().calGrade(66); } public void calGrade(int points) { if (points >= 80) System.out.println("A"); else if (points >= 70) System.out.println("B"); else if (points >= 60) System.out.println("C"); else if (points >= 50) System.out.println("D"); else System.out.println("F"); System.out.println("End calGrade."); } }

ผลลัพธ์ของโปรแกรม B End F End A End C End

calGrade. calGrade. calGrade. calGrade.

Related Documents


More Documents from "Bank"

Aim Star
June 2020 19
June 2020 18
June 2020 17