C# Tutorial Footage No.2 [Conversion of Values]
original exercises found here in Japanese.
https://ufcpp.net/study/csharp/exercise.html#1192
Task1: show the character code of any character typed into the console
- note that in order to get the very first letter from console input you - need to set the index[0] after the Console.Readline()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("This program tells you the character code of any 1 character\n"); | |
Console.Write("Enter 1 character \n"); | |
// get the very first letter of console input | |
char chara = Console.ReadLine()[0]; | |
// show the result on console | |
Console.Write("the character code ASCII[decimal] of {0} is {1}\n", chara, (int)chara); | |
} | |
} | |
} |
Task2: compare divisions are evaluated differently with different value types such as integer types and floating point number types
SKIPPED!!!Task3: Observe how double type numbers are round up or round down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("This program casts doubles into integers \n"); | |
Console.Write("{0} => {1}\n", 1.2, (int)1.2); | |
Console.Write("{0} => {1}\n", 0.8, (int)0.8); | |
Console.Write("{0} => {1}\n", -1.2, (int)-1.2); | |
Console.Write("{0} => {1}\n", -0.8, (int)-0.8); | |
} | |
} | |
} |
コメント
コメントを投稿