teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

文法の修正

2021/09/05 02:27

投稿

jing02
jing02

スコア2

title CHANGED
File without changes
body CHANGED
@@ -3,9 +3,15 @@
3
3
  ・英字と数字の両方を含む必要が有る
4
4
  ・同じ文字を 3 つ以上連続で使用することはできない
5
5
 
6
+ 入力される値
7
+ t
8
+
9
+ 1 ≦ (t の長さ) ≦ 30
10
+ 文字列 t は半角英字あるいは半角数字で構成された文字列
6
11
  英字の大文字と小文字は区別する必要はない
7
- 文字列が条件を満たす場合"success"
12
+ 文字列が全ての条件を満たす場合のみ"success"
8
- うでない場合は"fail" と出力する
13
+ れ以外全て"fail" と出力する
14
+
9
15
  ### 作成したコード
10
16
  ```
11
17
  using System;
@@ -13,6 +19,7 @@
13
19
 
14
20
  class Program
15
21
  {
22
+
16
23
  static bool sameCharactersOverThree(string line)
17
24
  {
18
25
  int charCount = 1;
@@ -28,6 +35,8 @@
28
35
  }
29
36
  }
30
37
  }
38
+ return true;
39
+ }
31
40
 
32
41
  static void Main()
33
42
  {
@@ -35,10 +44,8 @@
35
44
  Regex re = new Regex(@"[0-9]");
36
45
  Regex ge = new Regex(@"[A-z]");
37
46
 
38
- if (sameCharactersOverThree(line))
47
+ if (sameCharactersOverThree(line) && re.Matches(line).Count != 0 && ge.Matches(line).Count != 0 && line.Length >= 5)
39
48
  {
40
- if (re.Matches(line).Count != 0 && ge.Matches(line).Count != 0 && line.Length >= 5)
41
- {
42
49
  Console.WriteLine("success");
43
50
  }
44
51
  else
@@ -47,19 +54,13 @@
47
54
  }
48
55
  }
49
56
  }
50
- }
51
- }
52
57
  ```
53
- ###エラーメッセージ
58
+ ###エラーメッセージ(変更前)
54
59
  Main.cs(22,8): error CS1525: Unexpected symbol `static'
55
60
  Main.cs(22,16): error CS1547: Keyword `void' cannot be used in this context
56
61
  Main.cs(22,24): error CS1525: Unexpected symbol `('
57
62
  Main.cs(41,0): error CS1525: Unexpected symbol `}'
63
+ ###
58
64
 
59
-
60
- ```
65
+ ###追記
61
- Visual Studio2019では ロカル関数'Main'使用れてない、
66
+ 修正したらコ動きました。皆ん本当にありがとうござます。エラーメッセージをしっかり読むべきでした。
62
- 'Program.sameCharactersOverThree(string)'が値を返さないコードパスがあると表示されるので
63
- ここに何らかの原因があるということは何となく分かっているのですが・・・
64
-
65
- どうかお願い致します。