怎么用java修改代码 java修改器
Java 要实现此功能 代码应该如何修改?
Connection conn;
成都创新互联专注于企业成都全网营销、网站重做改版、万载网站定制设计、自适应品牌网站建设、H5高端网站建设、商城网站开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为万载等各大城市提供网站开发制作服务。
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:taian", "hr", "hr"); //连接Oracle
conn.setAutoCommit(false);
Statement myStat = conn.createStatement();
String sqlTxt = "update BankAccount set account=account-" + this.amount.getText() + " where accId=" + this.payOut.getText();
System.out.println("第一步 执行:" + sqlTxt);
//
try {
int affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇出方扣减" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.");
sqlTxt = "update BankAccount set account=account+" + this.amount.getText() + " where accId=" + this.saveIn.getText();
System.out.println("第二步 执行:" + sqlTxt);
affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇入方增加" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.");
// 事务成功结束, 提交
conn.commit();
} catch (SQLException sqlEx) {
System.out.println
sqlEx.printStackTrace();
// 事务中断,整体回滚到事务开始前状态
conn.rollback();
}
myStat.close();
conn.close();
} catch (Exception ex) {
System.out.println("反正是出错了.");
}
}//
JAVA代码修改
你的代码有很多问题,最主要的一个吧就是你的inverse函数的参数没传进去,你自己定义一个空矩阵num[][],计算秩,怎么算都是零,然后就返回 null,自然就报空指针异常了。我改好了程序,供你参考:
import java.util.Scanner;
public class Project2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请依次输入:a11、a12、a13、a21、a22、a23、a31、a32、a33\n");
int i, j;
double[][] number = new double[3][3];
double[][] number0 = new double[3][3];
for (i = 0; i 3; i++)
for (j = 0; j 3; j++)
number[i][j] = input.nextDouble();
System.out.println("Input Matrix is :");
System.out.println(number[0][0] + " " + number[0][1] + " "
+ number[0][2]);
System.out.println(number[1][0] + " " + number[1][1] + " "
+ number[1][2]);
System.out.println(number[2][0] + " " + number[2][1] + " "
+ number[2][2]);
number0 = inverse(number);
if (number0 != null) {
System.out.println("Inverse Matrix is :");
System.out.println(number0[0][0] + " " + number0[0][1] + " "
+ number0[0][2]);
System.out.println(number0[1][0] + " " + number0[1][1] + " "
+ number0[1][2]);
System.out.println(number0[2][0] + " " + number0[2][1] + " "
+ number0[2][2]);
} else
System.out.println("矩阵的秩为零");
}
public static double[][] inverse(double[][] A) {
double z;
double A1, B, C, D, E, F, G, H, I;
// double [][] num = new double [3][3];
double[][] num0 = new double[3][3];
System.out.println("Inverse Matrix A is :");
System.out.println(A[0][0] + " " + A[0][1] + " " + A[0][2]);
System.out.println(A[1][0] + " " + A[1][1] + " " + A[1][2]);
System.out.println(A[2][0] + " " + A[2][1] + " " + A[2][2]);
z = A[0][0] * A[1][1] * A[2][2] + A[2][0] * A[0][1] * A[1][2] + A[0][2]
* A[1][0] * A[2][1] - A[0][2] * A[1][1] * A[2][0] - A[0][0]
* A[1][2] * A[2][1] - A[2][2] * A[1][0] * A[0][1];
if (z == 0)
return null;
else {
A1 = A[0][0];
B = A[0][1];
C = A[0][2];
D = A[1][0];
E = A[1][1];
F = A[1][2];
G = A[2][0];
H = A[2][1];
I = A[2][2];
num0[0][0] = 1 / z * (E * I - F * H);
num0[0][1] = 1 / z * (C * H - B * I);
num0[0][2] = 1 / z * (B * F - C * E);
num0[1][0] = 1 / z * (F * G - D * I);
num0[1][1] = 1 / z * (A1 * I - C * G);
num0[1][2] = 1 / z * (C * D - A1 * F);
num0[2][0] = 1 / z * (D * H - E * G);
num0[2][1] = 1 / z * (B * H - A1 * H);
num0[2][2] = 1 / z * (A1 * E - B * D);
return num0;
}
}
}
你好请问这个java代码怎么修改?
你的主函数没有错误,你应该恢复主函数原来的样子public static void main(String[] args){
User user=new User();
user.setId(1001);
user.setName("user");
user.setStuNum("1001");
new TicketBooker(user);
}你的Java程序是在109行JCB_Year.setSelectedIndex(date.getYear()+1900-Integer.parseInt(arrayYear[0]));这句出问题了,因为今年是2018年,date.getYear()+1900=2018,2018-2014=4,JCB_Year.setSelectedIndex(4);而你的private JComboBox JCB_Year=new JComboBox(arrayYear);arrayYear是只定义了三个字符串的数组
private static final String arrayYear[]={"2014","2015","2016"};所以造成JComboBox下标Index越界,本来下标只有0到2你访问到了4.改正办法把arrayYear数组加两个元素,把private static final String arrayYear[]={"2014","2015","2016"};改成private static final String arrayYear[]={"2014","2015","2016","2017","2018"};就没问题了.注意,arrayYear数组 2019年还需要加"2019",2020年还需要加"2020"
本文题目:怎么用java修改代码 java修改器
链接地址:http://scyanting.com/article/dooiigg.html