我正在尝试使用以下代码来计算用户输入的一组值的平均值,并将其显示在a中,jTextArea但它无法正常工作.比如,用户输入7,4和5,程序显示1作为应显示5.3的平均值
ArrayList <Integer> marks = new ArrayList();
Collections.addAll(marks, (Integer.parseInt(markInput.getText())));
private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {
analyzeTextArea.setText("Class average:" + calculateAverage(marks));
}
private int calculateAverage(List <Integer> marks) {
int sum = 0;
for (int i=0; i< marks.size(); i++) {
sum += i;
}
return sum / marks.size();
}
Run Code Online (Sandbox Code Playgroud)
代码有什么问题?
我需要用另一个表和用户创建一个新的"auth"配置.我有一个表用于"admin"用户,另一个表用于普通用户.
但是,如何Auth使用不同的配置创建另一个实例?
假设我有两个表Employee和Locations.另外,我有一个视图viewEmpLocation,它是通过加入Employee和Locations来实现的.
如果我更新视图,原始表中的数据是否会更新?
我试图解析XML文件,<?version = 1.0, encoding = UTF-8>
但遇到了错误消息invalid byte 2 of 2-byte UTF-8 sequence.有谁知道导致这个问题的原因是什么?
我什么都不知道Web服务,我只是想调用一些由wsdl描述的"isAlive"服务.
在我看来这似乎不应该超过2-5行代码,但我似乎找不到任何东西,只有大量长的例子涉及第三方包等.
有人有什么想法吗?如果它总是被认为是长的可能是一个很好的解释,为什么它必须如此复杂也将不胜感激.我正在使用Eclipse,而wsdl是SOAP.
我有一个.warJava Web应用程序的文件.现在我想将它上传到我的ftp服务器,以便我可以执行它.
我应该执行哪些步骤来运行它?
webapp的上下文路径是/ mywebapp
实际上,我的ftp服务器名称是ftp://bilgin.ath.cx/,我已经将我的TestWebApp.war文件上传到这个目录:ftp://bilgin.ath.cx/web
那么访问webapplication 的index.html页面的URL应该是什么
Tomcat 在听 8082
Apache使用jk连接器访问Tomcat.
我正在使用Jersey API进行Web服务.我正在从客户端向服务器发送多部分数据.Web服务开始执行时,我遇到异常.
@POST
@Path("uploadphoto")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
public String uploadNotices(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
String uploadedFileLocation = "d:/" + fileDetail.getFileName();
// save it
try {
writeToFile(uploadedInputStream, uploadedFileLocation);
} catch(Exception e) {
return "no";
}
return "yes";
}
// save uploaded file to new location
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws Exception {
OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
int read = 0;
byte[] bytes = new byte[1024];
out = new FileOutputStream(new File(uploadedFileLocation));
while ((read = uploadedInputStream.read(bytes)) != -1) …Run Code Online (Sandbox Code Playgroud) 我有以下问题.我有3个实体,我正在使用OneToOne单向:
ENTITY1
@Entity
public class Entity1 implements Serializable{
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
Long id;
String name;
String value;
}
Run Code Online (Sandbox Code Playgroud)
ENTITY2
@Entity
public class Entity2 implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@OneToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST})
Entity1 entity1;
public Entity1 getEntity1() {
return entity1;
}
String name;
String value;
}
Run Code Online (Sandbox Code Playgroud)
ENTITY3
@Entity
public class Entity3 implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Long id;
@OneToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST})
private Entity1 entity1;
public Entity1 getEntity1() {
return entity1;
}
public void setEntity1(Entity1 entity1) {
this.entity1 = entity1;
} …Run Code Online (Sandbox Code Playgroud) 我有一个网站,获得了大量的点击,我遇到了问题,JDCB连接错误.
我对关闭有点困惑PreparedStatement,我需要关闭PreparedStatement还是只关闭Statement才关闭.
那么ResultSet,我需要关闭它吗?