我想将一个字符串(二进制数字)转换成Integer如下所示:
Integer.parseInt("011000010110")
Run Code Online (Sandbox Code Playgroud)
我总是得到一个NumberFormatException.数字位数太高了吗?
是否可以缩短java中方法的参数.
例如
public void testing(String A, String B, String C, JButton A, JButton B, JButton C){
}
Run Code Online (Sandbox Code Playgroud)
由于我有3个String变量和3个按钮,因此可以以任何方式缩短它.我试过了String A,B,C JButton A,B,C但是没有用.
我想创建一个包含播放器列表以及它们所在的竞技场的数组.我不知道哪种类型的阵列最适合.
它将保存这样的信息:
PlayerName : Arena
John : Arena1
Harry : Arena1
Dave : Arena2
Will : Arena2
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助,我是Java的新手,无法在网站上看到这个,如果是,请指向我那个方向:)
我有以下代码,
public class HttpAdapter extends HttpServlet {
private static final long serialVersionUID = 1L;
static Logger l = Logger.getLogger(HttpAdapter.class.getName());
public HttpAdapter() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
Layout ll = new SimpleLayout();
Appender a = new FileAppender();
a = new FileAppender(ll,"C:\\Users\\Vasanth\\Desktop\\JDlogs\\my.txt");
l.info(request.getRemoteHost());
l.addAppender(a);
String loc = DTO.findMyLocation();
l.info(loc);
l.info(this.getClass()+" >>>>>>>>>>>>>>task complete");
l.info(request.getRemoteHost());
}catch(Exception e){
e.printStackTrace();
}finally{
getServletContext().getRequestDispatcher("/JSP/done.jsp").forward(request, response);
}
}
//F:\\home\\WorkSpace\\Jdfront1\\webapps\\JSP\\
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
} …Run Code Online (Sandbox Code Playgroud) 我不明白为什么这会超出范围,你能帮助我吗?
会发生什么:
出于某种原因,在列表中的第一项之后,它超出范围,但我不知道为什么.
import java.util.Scanner; //import scanner
public class project2 {
public static void main (String[] args){
Scanner input = new Scanner(System.in); //scanner for input
int a = 0;
double [] lista = new double [a]; //create array
double [] listb = new double [a]; //create array
System.out.println("How long are the lists? ");
System.out.print("(The lists should be the same length): ");
a = input.nextInt();
int count=1;
System.out.println("Enter numbers for list A:");
for(int j = 0; j < a-1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,如果在给定的数量中存在相同数量的赔率和偶数,它会工作得很好但是它想要使用条件运算符而不是这4行(//行),
我明白了:
令牌"%"上的语法错误,AssignmentOperator无效
有人可以告诉我为什么吗?怎么了?
while(number!=0) {
//if(number%2==0)
//even++;
//else
//odd++;
number%2==0 ? even++ : odd++;
number/=10;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用具有以下技术堆栈的3层Web应用程序:
我们使用Mozilla Firefox浏览器启动此应用程序.我的问题是,应用程序在数据库上有大量数据时会遇到性能问题.
我们有大约10个JSP,而每个JSP与数据库中的特定表相关.加载表中包含大量数据的特定JSP时会出现此问题.登录到应用程序也遇到了性能问题,这也需要很长时间才能显示主页.
我需要这个应用程序以最佳性能工作.由于性能问题,我们不想失去我们宝贵的客户.我不知道瓶颈在哪里,以及如何调整应用程序的性能.
如果我使用@Autowired,这个servlet中的服务为null,它使用context.getBean(); 此外,使用/ floorOperationWS /的映射没有完成,我必须在web.xml中定义映射.
package com.confloorapp.services.endpoint;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
@WebServlet(value = "/floorOperationWS/")
public class UpdateFloorEventServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
FloorService floorService = (DoorService)context.getBean("floorService");
}
}
Run Code Online (Sandbox Code Playgroud)
这里是applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
<!-- Activates various annotations to be …Run Code Online (Sandbox Code Playgroud) 假设我有2个字段的类:x和y,类型double.是否可以定义2个构造函数,因此constructor1将创建对象,将其x属性设置为构造函数中的哪个参数告诉y默认值,构造函数2反之亦然?
public class Test {
private int x;
private int y;
public Test(int x) {
this.x = x;
}
public Test(int y) {
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样的东西,我知道它因为超载规则而无法工作
我试图插入一个表,其主键设置为使用预准备语句自动递增.
表中的字段如下;
id,用户名,密码,电子邮件,名字,姓氏
我的代码是这样的
String sql = "INSERT INTO Users values (?,?,?,?,?, ?)";
RegistrationStatus status = null;
Connection conn = null;
PreparedStatement st = null;
try {
conn = source.getConnection();
st = conn.prepareStatement(sql);
st.setString(2, username);
st.setString(3, password);
st.setString(4, email);
st.setString(5, firstname);
st.setString(6, lastname);
st.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
在我读过的地方,我们不应该包含第一个项目,因为数据库会处理它.对我而言,这种方法似乎失败了.
是否可以获得一些如何解决这个问题的帮助?
java ×10
servlets ×2
arrays ×1
constructor ×1
jsp ×1
list ×1
methods ×1
overloading ×1
spring ×1
spring-mvc ×1
sql ×1
swing ×1
tomcat ×1