扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
你的代码有很多问题,最主要的一个吧就是你的inverse函数的参数没传进去,你自己定义一个空矩阵num[][],计算秩,怎么算都是零,然后就返回 null,自然就报空指针异常了。我改好了程序,供你参考:
创新互联建站是专业的禹州网站建设公司,禹州接单;提供成都网站设计、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行禹州网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
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;
}
}
}
包lipei;
进口java.awt.FileDialog中;
进口java.awt.Frame中;
进口java.awt.Menu中;
进口java.awt.MenuBar中;
进口java.awt.MenuItem中;
进口java.awt.event.ActionEvent;
进口java.awt.event.ActionListener;
进口java.awt.event.WindowAdapter ;
进口java.awt.event.WindowEvent中;
进口javax.swing.Icon;
进口javax.swing.ImageIcon中;
进口javax.swing.JLabel中;
公共类BufferTest {
@ SuppressWarnings(“折旧”)
公共静态无效的主要(字串[] args){
/ / TODO代码应用程序的逻辑在这里
最后一帧F =新框架(“打开”);/ /标题
f.setBounds(100,100,400,300);
最后的JLabel LBL =新的JLabel(); BR / f.addWindowListener(新WindowAdapter(){
公共无效windowClosing(WindowEvent E){
System.exit(0);
}
});
的MenuBar MB =新的菜单栏();
菜单M1 =新菜单(“photolist”);
菜单项MI2 =新的MenuItem(“打开”);
最后FileDialog的FD =新文件对话框(F,“照片公开”,是FileDialog.LOAD);
fd.show();
mi2.addActionListener(新的ActionListener(){/ /打开文件夹
公共无效的actionPerformed(ActionEvent的E){
如果{
fd.show()(fd.isShowing()!);
}
字符串文件名= fd.getDirectory()+ fd.getFile();
图标图标=新的ImageIcon(文件名,“”);
lbl.setIcon(图标);
System.out的。的println(fd.getDirectory()+ fd.getFile()); / /显示图片的路径和名称
}
});
m1.add(MI2);
mb.add(M1);
f.setMenuBar(MB);
f.add(LBL);
f。秀();
}
}
把这一段放在一个循环里,然后判断是否继续输入的值,如果继续,那就继续下一次循环,如果停止,则跳出循环
计算次数放在小循环里,每输入一次加1,在大循环里定义,每次大循环都会从0开始
while(true){
int count = 0;
int number = rand.nextInt(100);
System.out.print("Your guess?");
int guess = console.nextInt();
do{
if (guess number){
count++;
System.out.println("It's lower.");
System.out.print("Your guess?");
guess = console.nextInt();
i++;
}else if (guess number){
System.out.println("It's higher.");
System.out.print("Your guess?");
guess = console.nextInt();
i++;
}
}while(guess != number);
if(guess == number){
System.out.println("You got it right in " + i + " guesses!");
System.out.println("Do you want to play again?");
String line = console.nextLine();
if (line.startsWith("Y")||line.startsWith("y")) {
guess();
}else if (line.startsWith("N")||line.startsWith("n")) {
break;
}
}
}
Connection conn;
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("反正是出错了.");
}
}//
我修改成可以运行的程序了,但不知道是不是你想要代码效果。
public class TestprintString
{
public static void printString(String[] args)
{
if(args != null)
{
int len = args.length;
for(int i = 0; i len;i++)
{
System.out.println(args[i]+",");
}
System.out.println();
}
}
public static void main(String args[]){
printString(new String[]{"abc", "def", "hij"});
}
}
首先我先说下jdk是不支持泛型的,但是可以用强制转型的方式
1.去掉每个类的的东西,如改写成List sockets=new ArrayList();报错的地方用强制转型的方式改写,如(Socket) socket
2.ChatToMul这个类中for循环改写为Iterator
for(Iterator it = sockets.iterator();it.hasNext();){
Socket socketto = (Socket) it.next();
PrintWriter pw=MyUtil.getPrintWriter(socket);
PrintWriter pwto=MyUtil.getPrintWriter(socketto);
pw.println(socket.getRemoteSocketAddress().toString()+"对"+
socketto.getRemoteSocketAddress().toString()+"说:"+message);
pw.flush();
pwto.println(socket.getRemoteSocketAddress().toString()+"对"+
socketto.getRemoteSocketAddress().toString()+"说:"+message);
pwto.flush();
}
这样基本改写成功。
如果需要源代码话,就联系我,我传给你,
代码改写不易,望采纳
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流