Code Fix

初級missing return statement の原因と直し方 › パターン1

missing return statement の原因と直し方

すべての経路で値を返す必要があります。

 1  public class Main {
 2      static int twice(int n) {
 3          ______ n * 2;
               ^
 4      }
 5      public static void main(String[] args) {
 6          System.out.println(twice(3));
 7      }
 8  }
Main.java:3: error: not a statement

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

missing return statement の原因と直し方

ifだけで分岐したときに漏れる道を可視化します。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)