前提・実現したいこと
for文の入れ子、ネストをしたい。
最後のfor文において、for文を繰り返し3回使って表示するのではなくて、
for文のfor文を使って表示したい。
発生している問題・エラーメッセージ
String[] userProfile(int num){
String snum = String.valueOf(num);
String[][] profile_list = { {"1","技育太郎","東京","男","プログラマー"},
{"2","技育花子","北海道","女","システムエンジニア"},
{"3","技育三郎","大阪","男","Webエンジニア"} };
for (String[]userProfile : profile_list){
if (snum.equals(userProfile[0])){
return userProfile;
}
} return null; } /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Method8</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet Method8 at " + request.getContextPath() + "</h1>"); String[] user = userProfile(1); for (int i = 1; i<user.length; i++){ out.print(user[i]); } String[] userr = userProfile(2); for (int i = 1; i<userr.length; i++){ out.print(userr[i]); } String[] userrr = userProfile(3); for (int i = 1; i<userrr.length; i++){ out.print(userrr[i]); }
該当のソースコード
String[] user = userProfile(1);
for (int i = 1; i<user.length; i++){ out.print(user[i]); } String[] userr = userProfile(2); for (int i = 1; i<userr.length; i++){ out.print(userr[i]); } String[] userrr = userProfile(3); for (int i = 1; i<userrr.length; i++){ out.print(userrr[i]); }
試したこと
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/18 13:38
2018/12/18 13:42