카테고리 없음
2018.03.08 수업내용
일등하이
2018. 5. 15. 21:19
반응형
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { //비밀번호를 입력해주세요. [입력] //비밀번호를 재 입력 해주세요. [입력] //비밀번호와 재 입력한 비밀번호가 다를경우 //비밀번호가 틀렸네요. //비밀번호를 입력해주세요. [입력] //비밀번호를 재 입력 해주세요. [입력] //비밀번호와 재 입력한 비밀번호가 같은 경우 //비밀번호 설정이 완료 되었습니다. //프로그램을 종료 합니다. string password = ""; //처음 입력 받을 비밀번호 string checkPassword = ""; //두번째 확인을 위해 입력 받을 비밀번호 while (true) { Console.Write("비밀번호를 입력해주세요"); password = Console.ReadLine(); Console.Write("비밀번호 확인을 위해 다시 입력해주세요"); checkPassword = Console.ReadLine(); if (password == checkPassword) { Console.WriteLine("프로그램을 종료 합니다."); break; } else { Console.Clear(); } } Console.ReadKey(); } } } | cs |
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 56 57 58 59 60 61 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int weaponId = 0; string weaponName = ""; bool isReSelectWeapon = false; while (true) { Console.Write("지급받을 무기를 선택해주세요. (1:검, 2:도끼)"); bool result = int.TryParse(Console.ReadLine(), out weaponId); if (result) { //숫자로 변환 가능한 문자열 입력됨 "1234" if (weaponId == 1) { //검 weaponName = "검"; break; } else if (weaponId == 2) { //도끼 weaponName = "도끼"; break; } else { //잘못입력 한거임 isReSelectWeapon = true; goto RE_SELECT_WEAPON; } } else { //숫자로 변환 불가능한 문자열 입력된 "검" Console.WriteLine("-----> 숫자로 변환 불가능한 문자열이 입력 됨"); } } RE_SELECT_WEAPON: if (isReSelectWeapon) { Console.Write("1:검, 2도끼중 하나를 선택해주세요."); } Console.Write("--->" + weaponName + "을 선택 했습니다."); Console.ReadKey(); } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //아이디를 입력해주세요. [입력] //입력한 아이디가 000 맞습니까 (예/아니오) [입력] //틀리다면 //그럼 다른 아이디를 입력해주세요. [입력] //입력한 아이디가 000 맞습니까 (예/아니오) [입력] //맞다면 //비밀번호를 입력해주세요. [입력] //비밀번호 확인을 위해 다시 입력해주세요. [입력] //비밀번호와 재 입력한 비밀번호가 맞다면 //직업을 선택해주세요 (1: 전사, 2:마법사, 3:도적) //틀리다면 //비밀번호가 틀리셨구요. 그럼 다른 비밀번호를 입력해주세요. [입력] //비밀번호 확인을 위해 다시 입력해주세요. [입력] //직업이 선택되었을경우 //전사: 검, 마법사: 지팡이, 도적: 단검을 지급 한다. //명령어를 입력해주세요 : "끝", "처음으로" | cs |
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { //string rogue = "가방 집어"; //string s = rogue.Replace(" 집어", ""); //Console.WriteLine(s); //길바닥에 떨어져있는 물건을 <물건> <집어> 라는 명령어를 통해 집는다. [입력] //Replace를 사용해서 떨어져있는 물건의 이름을 출력 하세요. //이쑤시개 집어 //이쑤시개를 집었습니다. //도시락 집어 //도시락을 집었습니다. //끝 while (true) { Console.WriteLine("<물건> <집어> 명령어를 통해 무언가를 집으세요."); string command = Console.ReadLine(); if (command == "끝") { break; } else { bool isContain = command.Contains(" 집어"); if (isContain) { Console.WriteLine(command.Replace(" 집어", "") + "를 집었습니다."); } } } Console.ReadKey(); } } } | cs |
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp1 { class Program { static void Main(string[] args) { //Replace, String strName = "도적"; string replacedName = strName.Replace("도적", "산적"); Console.WriteLine(replacedName); //산적 //Contains, bool isContain = strName.Contains("산적"); Console.WriteLine(isContain); //Equals, bool isEqual = strName.Equals("도적"); Console.WriteLine(isEqual); //Length int length = strName.Length; Console.Write(length); Console.ReadKey(); } } } | cs |
1 2 3 4 5 | ConsoleKeyInfo info = Console.ReadKey(); if (info.Key == ConsoleKey.Enter) { } | cs |
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp5 { class Program { //색상입혀서 출력 하는거 public static string ColoredConsoleWrite(ConsoleColor color, string text) { ConsoleColor originalColor = Console.ForegroundColor; Console.ForegroundColor = color; Console.Write(text); Console.ForegroundColor = originalColor; return text; } //한줄 지우는거 public static void ClearCurrentConsoleLine() { int currentLineCursor = Console.CursorTop; Console.SetCursorPosition(0, Console.CursorTop); Console.Write(new string(' ', Console.WindowWidth)); Console.SetCursorPosition(0, currentLineCursor); } static void Main(string[] args) { ColoredConsoleWrite(ConsoleColor.Yellow, "안녕하세요"); Console.WriteLine(); PRESS_ENTER_KEY: Console.WriteLine("엔터를 치세요"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { Console.WriteLine("엔터를 치셨군요 훌륭 합니다."); } else { ClearCurrentConsoleLine(); goto PRESS_ENTER_KEY; } Console.ReadKey(); } } } | cs |
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace study2 { class Program { static void Main(string[] args) { int number; string input = Console.ReadLine(); //입력을 받습니다. bool result = Int32.TryParse(input, out number); //문자열로 입력한 숫자 표현을 정수형으로 변환 가능한지 알아보는 API Console.Write("입력한 문자열 숫자표현이 정수로 변환되는지 ? " + result + " , " + number); } } } |
반응형