C#/Problems 16

6. 문자열에 특정 문자열이 포홤되는 지 확인하기( Contains( ) )

1. 코드 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.Tasks; namespace Study_013_1 { class App { public App() { string s1 = "the Lazy dog, fox"; string s2 = "fox"; bool b; b = s1.Contains(s2); //s2가 s1에 포함되면 true / 포함되지 않으면 false Console.WriteLine("{0}", b); //True..

C#/Problems 2020.04.21

5. 한 줄 출력시 ( Console.Write( ); ) 입력을 다음 줄로 넘기기, 마지막 쉼표 없애기

1. 코드 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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study_013_1 { class App { public App() { int length = 3; int j = 0; for(int i=0; i=length-1) { Console.Write("{0}", i); Console.WriteLine(); } else { Console.Wri..

C#/Problems 2020.04.21

3. 입력받은 문자열을 부동소수점으로 변환하기(string to float)

1. 문제 Console.ReadLine( ) 으로 입력받은 문자열 값을 float 값으로 변환하고자 함. 2. 해결하기 float.Parse( ) 문자열을 부동소수점 형식으로 변환한다. 1 2 3 4 5 6 7 8 // 입력값을 소수점 형식으로 변환하기 Console.Write("소수 입력: "); string input = Console.ReadLine(); float number = float.Parse(input); Console.WriteLine("\n출력: {0}",number);

C#/Problems 2020.04.08

1. 정수값끼리 나누었는데 0이 나올때

1. 문제 과제를 하던 중에 변수 2개를 이용하여 50% 라고 출력을 하고 싶어서 연산을 했는데 0만 나왔다. 1 2 3 4 5 //50% 출력하기 int a=5; int b=10; Console.WriteLine(a/b*100+"%"); 2. 해결 두 int형식 변수 중 하나를 float로 바꾼다. 1 2 3 4 5 //50% 출력하기 int a=5; float b=10f; Console.WriteLine(a/b*100+"%");; 5/10 의 값은 0.5가 나오는데 둘다 정수형일 경우 0.5가 0이 되어서 0만 출력된다. Ms Docs에 따르면 정수형식과 float, double, decimal은 혼합하여 연산이 가능하다. float, double은 정수와 연산할 경우 암시적으로 부동 소수점 형식 중..

C#/Problems 2020.04.05