package home;
public class pro {
int sx,number;
int[] y1=new int[500];
int[] m1=new int[500];
String[] v=new String[500];
int[] year=new int[500];
int[] month=new int[500];
double[] v1=new double[500];
double[] v2=new double[500];
double[] sol=new double[500];
double[][] x=new double[1000][10];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
String db,tab;
db="sou";
tab="sou";
select_home sub=new select_home();
sub.makedata(db,tab,"c6");
number=sub.number;
v=sub.v;
y1=sub.year;
m1=sub.month;
int s;
int yy,mm;
yy=2003;
mm=1;
for(s=1;s<60;s++){
mm=mm+1;
if(mm>4)yy=yy+1;
if(mm>4)mm=1;
year[s]=yy;
month[s]=mm;
}
int h,m3;
for(s=1;s<49;s++){
v1[s]=0;
for(sx=1;sx<number+1;sx++){
h=0;
if(y1[sx]==year[s])h=h+1;
m3=(m1[sx]-1)/3+1;
if(m3==month[s])h=h+1;
if(h==2)v1[s]=v1[s]+num(v[sx]);
}
}
db="gdp";
tab="gdp";
String c1;
select sub2=new select();
sub2.makedata(db,tab,"mg","c5");
number=sub2.number;
v=sub2.v;
y1=sub2.year;
m1=sub2.month;
for(s=1;s<49;s++){
for(sx=1;sx<number+1;sx++){
h=0;
if(y1[sx]==year[s])h=h+1;
if(m1[sx]==month[s])h=h+1;
if(h==2)v2[s]=num(v[sx]);
}
}
for(s=1;s<49;s++){
x[s][1]=1;
x[s][2]=v1[s];
}
ols sub3=new ols();
sub3.datanumber=48;
sub3.number=2;
sub3.x=x;
sub3.y=v2;
sub3.makedata();
sol=sub3.sol;
for(s=1;s<49;s++){
System.out.println(year[s]+"年"+month[s]+"期,"+(sol[1]+sol[2]*v1[s])+","+v2[s]);
}
}
int numx(String str){
int nx;
nx=0;
try{
nx=Integer.parseInt(str);
}catch (Exception e) {}
return nx;
}
double num(String str){
double nx;
nx=0;
try{
nx=Double.parseDouble(str);
}catch (Exception e) {}
return nx;
}
}
package home;
public class ols {
int s,s1,s2;
int datanumber,number;
double x1;
double[][] a=new double[100][100];
double[] b=new double[100];
double[] y=new double[1000];
double[][] x=new double[1000][10];
double[] sol=new double[100];
void makedata(){
for(s1=1;s1<number+1;s1++){
for(s2=1;s2<number+1;s2++){
x1=0;
for(s=1;s<datanumber+1;s++){
x1=x1+x[s][s1]*x[s][s2];
}
a[s1][s2]=x1;
}
}
for(s1=1;s1<number+1;s1++){
x1=0;
for(s=1;s<datanumber+1;s++){
x1=x1+x[s][s1]*y[s];
}
b[s1]=x1;
}
double z;
for(s1=1;s1<number+1;s1++){
for(s2=1;s2<number+1;s2++){
z=a[s2][s1]/a[s1][s1];
if(s1==s2)z=0;
for(s=1;s<number+1;s++){
a[s2][s]=a[s2][s]-z*a[s1][s];
}
b[s2]=b[s2]-z*b[s1];
}
}
for(s1=1;s1<number+1;s1++){
sol[s1]=b[s1]/a[s1][s1];
}
}
}
package home;
import java.sql.*;
class select{
Connection dbx;
Statement stx;
String sqx;
ResultSet rsx;
int key;
String word;
int sx,number;
int[] year=new int[500];
String[] v=new String[500];
int[] month=new int[500];
void makedata(String db,String tab,String r1,String c1){
String url = "jdbc:h2:"+db+";create=true";
String usr = "";
String pwd = "";
try
{
Class.forName("org.h2.Driver");
dbx = DriverManager.getConnection(url, usr, pwd);
} catch (Exception ex) { ex.printStackTrace();}
sx=0;
try {
stx = dbx.createStatement();
sqx="select * from "+tab+" WHERE credit="+change(c1)+" and real="+change(r1);
rsx = stx.executeQuery(sqx);
if (rsx != null) {
while (rsx.next()) {
sx=sx+1;
v[sx]= rsx.getString("value");
year[sx]=rsx.getInt("year");
month[sx]=rsx.getInt("season");
}
}
number=sx;
rsx.close();
stx.close();
dbx.close();
} catch (Exception ex) {ex.printStackTrace();}
}
String change(String word){
String e;
e="'"+word+"'";
return e;
}
}
package home;
import java.sql.*;
class select_home{
Connection dbx;
Statement stx;
String sqx;
ResultSet rsx;
int key;
String word;
int sx,number;
int[] year=new int[500];
int[] month=new int[500];
String[] v=new String[500];
void makedata(String db,String tab,String c1){
String url = "jdbc:h2:"+db+";create=true";
String usr = "";
String pwd = "";
try
{
Class.forName("org.h2.Driver");
dbx = DriverManager.getConnection(url, usr, pwd);
} catch (Exception ex) { ex.printStackTrace();}
sx=0;
try {
stx = dbx.createStatement();
sqx="select * from "+tab+" where credit = "+change(c1);
rsx = stx.executeQuery(sqx);
if (rsx != null) {
while (rsx.next()) {
sx=sx+1;
v[sx]= rsx.getString("value");
year[sx]=rsx.getInt("year");
month[sx]=rsx.getInt("month");
}
}
number=sx;
rsx.close();
stx.close();
dbx.close();
} catch (Exception ex) {ex.printStackTrace();}
}
String change(String word){
String e;
e="'"+word+"'";
return e;
}
}
最終更新:2015年08月12日 09:02