Giter Site home page Giter Site logo

lab-05's Introduction

#ใบงานที่ 5 ##เรื่อง การใช้งานคำสั่ง Console.WriteLine() ##วัตถุประสงค์ 1). เพื่อให้นักศึกษาบอกวิธีการใช้คำสั่งแสดงผลบน Text Mode ในภาษา C# ได้ 2). เพื่อให้นักศึกษาสามารถปรับแต่งคำสั่งแสดงผลทางหน้าจอตามต้องการได้

##ขั้นเตรียมการทดลอง 1). สร้าง Project ตั้งชื่อเป็น Lab5 เพื่อทดลองการใช้งานคำสั่ง Console.WriteLine() ลำดับขั้นการทดลอง (หมายเหตุ ในรูปประกอบที่มี namespace เป็น Lab4 รบกวนแก้เป็น Lab5 ด้วยครับ) 2). ทดลองเรื่องจำนวนของอาร์กิวเมนต์ในคำสั่ง Console.WriteLine()

2.1). แก้โปรแกรมตามรูปด้านล่างนี้

2.2). รันโปรแกรม และบันทึกผลที่ได้

2.3). แก้โปรแกรมตามรูปด้านล่างนี้

2.4). รันโปรแกรม และบันทึกผลที่ได้

###คำถาม 5.1 เครื่องหมาย { } ในคำสั่ง Console.WriteLine() มีลักษณะการใช้งานอย่างไร

  • บอกว่าจะให้นำตัวเลขข้างหลังไปใส่ไว้ตรงไหน

###คำถาม 5.2 ถ้ามีการใช้ตัวเลขใน { } ที่กระโดด เช่น {0} {2} {3} จะใช้งานได้หรือไม่ อย่างไร จงอธิบาย

  • ใช่ได้แต่ตำแหน่งที่ว่างไว้จะขาด

2.5). แก้โปรแกรมตามรูปด้านล่างนี้

2.6). รันโปรแกรม และบันทึกผลที่ได้

3). ทดลองเรื่องการกำหนดความกว้างของอาร์กิวเมนต์

3.1). แก้โปรแกรมตามรูปด้านล่างนี้

3.2). รันโปรแกรม และบันทึกผลที่ได้

###คำถาม 5.3 การกำหนดความกว้างของอาร์กิวเมนต์ด้วยเครื่องหมาย { , } ในคำสั่ง Console.WriteLine() มีรูปแบบการใช้งานอย่างไร

  • กำหนดตำแหน่งที่เราอยากให้ตัวอีกษรของเราไปแสดง

4). ทดลองเรื่องการกำหนดรูปแบบของอาร์กิวเมนต์ 4.1). แก้โปรแกรมตามรูปด้านล่างนี้

4.2). รันโปรแกรม และบันทึกผลที่ได้

5). ทดลองเรื่องการกำหนดรูปแบบพร้อมความกว้างของอาร์กิวเมนต์ 5.1). แก้โปรแกรมตามรูปด้านล่างนี้

5.2). รันโปรแกรม และบันทึกผลที่ได้

6). ทดลองเรื่องการกำหนดรูปแบบพร้อมความกว้างของทศนิยมของอาร์กิวเมนต์ 6.1). แก้โปรแกรมตามรูปด้านล่างนี้

6.2). รันโปรแกรม และบันทึกผลที่ได้

แบบฝึกหัด จงระบุ output ของบรรทัดคำสั่งต่อไปนี้

1.  string name = "Hello";
    Console.WriteLine(String.Format("{0} there. I said {0}! {0}???", name)); //Hello there. i said Hello!
2.    Console.WriteLine("{2:d} {0:d} {1:d}", 1, 2, 3);  //2 1 3
3.    Console.WriteLine("Hello " + "World"); //Hello World
4.    Console.WriteLine("Here comes a slash \\"); //Here comes a slash \
5.    Console.WriteLine("|{0, 10}|", 999); //999
6.    Console.WriteLine("|{0,-10}|", 000); //0
7.    Console.WriteLine("The value: {0}.", 500); //The value: 500
8.    Console.WriteLine("The value: {0:C}.", 500); //The value:500.00
9.    Console.WriteLine("{0,-10:F4}", 12.3456789); //12.3456789
10.   Console.WriteLine("{0,-10:C}", 12.3456789); //12.35
11.   Console.WriteLine("{0,-10:E3}", 12.3456789); //1.235E+001
12.   Console.WriteLine("{0,-10:x}", 65535); //ffff
13.   Console.WriteLine("{0,-10:X}", 65535); //FFFF
14.   int i; 
      Console.WriteLine("Value\tSquared\tCubed"); 
      for(i = 1; i < 10; i++) 
          Console.WriteLine("{0}\t{1}\t{2}", i, i*i, i*i*i); 
15.    Console.WriteLine("{0:#.###}.", 1234.56789);  //1234.5678

lab-05's People

Contributors

koson avatar settapong123 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.