0% found this document useful (0 votes)
73 views4 pages

MR. MAMPAN SANGSA 50052535 วิชา Computer Programming: public class

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 !!!"); }

Uploaded by

Bank
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views4 pages

MR. MAMPAN SANGSA 50052535 วิชา Computer Programming: public class

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 !!!"); }

Uploaded by

Bank
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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);
[Link]();
new TestIfElse().calGrade(49);

public void calGrade(int points) {


if (points > 50) {
[Link]("Your points more than 50");
[Link]("Not Fail");

}
else {
[Link]("Your points less than 50");
[Link](" Fail !!!");
}
[Link]("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 number[][] = new int[10][];
int count = 1;
int num = 1;
for (int i = 0; i < 10; i++) {
number[i] = new int[count++];
for (int j = 0; j <= i; j++) {
number[i][j] = num++;
[Link](number[i][j] + "\t");

}
[Link]();
}

}
}

ผลลัพธ์ของโปรแกรม
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<[Link]; i++){/*[Link] ใช้หาขนาดอาร์เรย์s*/
s[i]=(char)('A'+i);/*กำหนดค่าอักษรให้แต่ละช่องของอาร์เรย์s*/

}
for (int i=0; i<[Link]; i++){
[Link](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.";
[Link](msg1);
[Link](msg2);
[Link](name1);
[Link](name2);
[Link](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)
[Link]("A");
else if (points >= 70)
[Link]("B");
else if (points >= 60)
[Link]("C");
else if (points >= 50)
[Link]("D");
else
[Link]("F");
[Link]("End calGrade.");
}

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

You might also like