วิชาภาษาจาวา (java)

คำสั่ง print ภาษาจาวา (java)

คำสั่ง print ในภาษาจาวา จะใช้ คำสั่ง System.out.print(); ซึ่งจะเป็นคำสั่งที่ค่อยข้างยาวมาก ๆ เมื่อเทียบกับภาษาไพทอนแต่ก็จะกว่ากว่าในภาษาซี

โครงสร้างคำสั่ง System.out.print();

System.out.print(); กับ System.out.println(); จะมีการแตกต่างกันตรงที่ ln คือการแสดงผลเสร็จแล้วจะขึ้นบรรทัดใหม่
การแสดงค่าตัวแปรร่วมกันให้อยู่ในบรรทัดเดียวกันจะใช้ + เข้ามาร่วมด้วย

class Printtest 
{
	public static void main(String[] args) 
	{
		int a = 10;
		float b = 10.5f;
		char c = 'A';
		String d = "เกรด";  //ข้อมูลประเภท string จะต้องอยู่ภายใน ""
		System.out.print(a);  //หากไม่ใส่ ln มันจะแสดงในบรรทัดเดียวกัน
		System.out.print(b);
		System.out.println("แสดงข้อความ");
		System.out.println("แสดงข้อความ"+a);
		System.out.println("แสดงข้อความ"+b);
		System.out.println("แสดงข้อความ"+c);
		System.out.println("แสดงข้อความ"+d);
		System.out.println("แสดงข้อความ"+a+b+c+d); //ข้อมูลประเภท string จะต้องอยู่ภายใน ""	
	}
}

 

slot gacor hari ini slot qris slot gacor maxwin slot online slot gacor gampang menang slot gacor hari ini slot online slot slot slot guci777 guci777 fafatogel fafatogel fafatogel fafatogel agen138 slot agen138 slot data hk bola slot bolaslot99 bola slot agen138 link alternatif koin138 link alternatif agen138 slot ag138 slot slot gacor slot thailand