06 กรกฎาคม, 2550

ตัวดำเนินการเชิงข้อความ

ตัวดำเนินการเชิงข้อความ
เป็นตัวดำเนินการที่ใช้สำหรับการจัดการกับข้อความ โดยการรวมเอาข้อมูลประเภทตัวแปร ตั้งแต่ 2 ตัวขึ้นไป เข้าด้วยกัน โดยที่ตัวดำเนินการประเภทนี้มีเพียงตัวเดียวนั้น คือ +



รูปแบบการใช้งาน
"ข้อความที่1" + "ข้อความที่2";ตัวแปรที่1 + ตัวแปรที่2;


ตัวอย่าง
text1="นี่คือข้อความ"+"ที่อยู่ในตัวแปร ชื่อ text1";

text2=" ส่วนนี้คือ"+"ข้อความจากตัวแปร ชื่อ text2";
text3=text1+text2;

โจทย์ที่ทำวันนี้

import java.util.*;
public class week6_7{
public static void main(String[]args){

Scanner inp1 = new Scanner(System.in);
double a,b,c,sum;
System.out.print("Input score 1 : ");
a = inp1.nextDouble();
System.out.print("Input score 2 : ");
b = inp1.nextDouble();
System.out.print("Input score 3 : ");
c = inp1.nextDouble();
sum = a+b+c;

if(sum>=50){
System.out.println("ผ่าน");
System.out.println("Take new course");
}

else{
System.out.println("ไม่ผ่าน");
System.out.println("เรียนซ้ำ");
}

System.out.println("Byebye");
}
}