把这个代码 int m=Integer.parseInt(recvStr); StringBuffer sb = new StringBuffer(); while(m!=0){ int m1 = m%10; m = m/10; sb.append(m1); } reString="这个整数首尾倒置之后为:"+sb;
时间: 2023-05-21 10:06:40 浏览: 63
把这个代码中的缺失的“+”号加上,正确的代码如下所示:
int m = Integer.parseInt(recvStr);
StringBuffer sb = new StringBuffer();
while(m!=0){
int m1 = m%10; // 修改这行,把“”改成“%”
m = m/10;
sb.append(m1);
}
reString = "这个整数首尾倒置之后为:" + sb;
相关问题
public String kaoshilist4() { HttpServletRequest request = ServletActionContext.getRequest(); String truename = request.getParameter("truename"); String username = request.getParameter("username"); StringBuffer sb = new StringBuffer(); sb.append(" where "); StringBuffer sb2 = new StringBuffer(); sb2.append(" where "); if(username!=null&&!"".equals(username)){ sb.append(" user.username like '%"+username+"%'"); sb.append(" and "); sb2.append(" user.username like '%"+username+"%'"); sb2.append(" and "); request.setAttribute("username", username); } if(truename!=null&&!"".equals(truename)){ sb.append(" user.truename like '%"+truename+"%'"); sb.append(" and "); sb2.append(" user.truename like '%"+truename+"%'"); sb2.append(" and "); request.setAttribute("truename", truename); } sb.append(" 1=1 order by id desc"); String where = sb.toString(); sb2.append(" 1=1 "); String where2 = sb2.toString(); int currentpage = 1; int pagesize = 20; if (request.getParameter("pageNum") != null) { currentpage = Integer.parseInt(request.getParameter("pageNum")); pagesize = Integer.parseInt(request.getParameter("numPerPage")); } int total = kaoshiDao.selectBeanCount(where2); request.setAttribute("list", kaoshiDao.selectBeanList((currentpage - 1)* pagesize, pagesize, where)); request.setAttribute("totalCount", total); request.setAttribute("ps", pagesize); request.setAttribute("pn", currentpage); request.setAttribute("url", "method!kaoshilist4"); this.setUrl("kaoshi/kaoshilist4.jsp"); return SUCCESS; }解释此代码
此代码是一个 Java Web 应用的一个 Action,用于返回考试列表的数据。主要实现逻辑是通过从 request 中获取参数,并拼接成查询语句,在数据库中查找对应的数据。其中,pageNum 和 numPerPage 是用于分页查询的参数,totalCount 是查询结果的总数,ps 和 pn 是分页需要的参数,url 是分页查询的链接地址。最终将查询结果和相应的参数设置到 request 中,然后跳转到 kaoshi/kaoshilist4.jsp 页面进行展示。
public List<SystemPort> getSystem(Integer pageNo, Integer length) { try { //编译 String encode = URLDecoder.decode(String.format(systemPort,pageNo,length), "UTF-8"); //发送 URL url = new URL(encode); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); //响应结果 缓存和加强性能 转为字节流 客户端:返回值 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); StringBuffer stringBuffer = new StringBuffer(); String inputLine; while ((inputLine = bufferedReader.readLine()) !=null){ stringBuffer.append(inputLine); } bufferedReader.close(); //转为集合对象 RegionResult regionResult = JSON.parseObject(stringBuffer.toString(), RegionResult.class); List<SystemPort> content = JSONArray.parseArray(JSON.toJSONString(regionResult.getData().get("content")), SystemPort.class); String totalElements = JSON.toJSONString(regionResult.getData().get("totalElements")); if(Integer.parseInt(totalElements)>content.size()){ getSystem(pageNo,Integer.parseInt(totalElements)); } return content; } catch (IOException e) { e.printStackTrace(); } return null;}
这段代码是一个Java方法,用于获取系统端口信息。该方法接收两个整数类型的参数pageNo和length,用于指定获取数据的起始页数和每页数据的长度。该方法通过HTTP协议向指定的URL发送GET请求,并解析响应结果。最终将解析结果转换为系统端口集合对象并返回。如果总元素数大于当前页的元素数,则会递归调用该方法获取所有数据。
阅读全文