首先你要在文檔頁設置一個統一的節點。最好在文檔的開始設置。
CTSectPrsectPr=XWPFDocument.getDocument.getBody.addNewSectPr();
CTPageSzpgSz=sectPr.addNewPgSz();
通過pgSz設置寬內度/高度和紙張容方向
//設置橫板
pgSz.setW(BigInteger.valueOf(15840));
pgSz.setH(BigInteger.valueOf(11907));
pgSz.setOrient(STPageOrientation.LANDSCAPE);
//設置豎版
pgSz.setH(BigInteger.valueOf(15840));
pgSz.setW(BigInteger.valueOf(11907));
pgSz.setOrient(STPageOrientation.PORTRAIT);
㈡ 編寫程序, 編寫程序,隨機生成10個兩位整數, 用冒泡法將它們從小到大進行排序
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main()
{
int i,j,t;
int a[10];
srand(time(NULL));
cout<<"隨機生成10個兩位整數:";
for(i=0;i<10;i++)
{
a[i]=10+rand()%90;
cout<<setw(3)<<a[i];
}
cout<<endl;
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(a[j]<a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
cout<<"用冒泡法將它們從小到大進行排序版:";
for(i=0;i<10;i++)
{
cout<<setw(3)<<a[i];
}
return 0;
} 運行結果截圖權:
㈢ 怎樣用java實現數字向右對齊
用格抄式襲化輸出就行了吧:
System.out.printf("%4.0f : 1\n",1.0);
System.out.printf("%4.0f : 10\n",10.0);
System.out.printf("%4.0f : 100\n",100.0);
System.out.printf("%4.0f : 1000\n",1000.0);
㈣ 用java語言編寫追趕法求解n階三對角方程組
可以這樣寫,代碼如下
#include "pch.h"
#include <iomanip>
#include <iostream>
# include <fstream>
#include <iomanip>
#include <math.h>
void Chasing_method(double **a, double *b, double *xx, int N_num);
using namespace std;
//*****************************
//追趕法求解AX=B矩陣
//*****************************
void Chasing_method(double **a, double *b, double *xx, int N_num)
{
int i, j, k;
double *gamma = new double[N_num]();
double *alpha = new double[N_num]();
double *beta = new double[N_num]();
double *y = new double[N_num]();
alpha[0] = a[0][0];
beta[0] = a[1][0] / alpha[0]; y[0] = b[0] / alpha[0];
for (i = 1; i < N_num; i++)
{
gamma[i] = a[i - 1][i];
alpha[i] = a[i][i] - gamma[i] * beta[i - 1];
if (i < N_num - 1)
{
beta[i] = a[i + 1][i] / alpha[i];
}
y[i] = (b[i] - gamma[i] * y[i - 1]) / alpha[i];
}
xx[N_num - 1] = y[N_num - 1];
for (i = N_num - 2; i >= 0; i--)
{
xx[i] = y[i] - beta[i] * xx[i + 1];
}
}
int main()
{
int N_num = 4;
double **a = new double*[N_num]();
for (int i = 0; i < N_num; i++) //AX=B方程a[n][n]為系數矩陣
a[i] = new double[N_num]();
double *b = new double[N_num](); //AX=B方程b[n]為右側列矩陣
double *x = new double[N_num](); //AX=B方程x[n]為方程解
ifstream fin("ab.txt");
for (int i=0; i < N_num; i++)
{
for (int j=0; j < N_num; j++)
{
fin >> a[i][j]; //讀取數
cout << fixed << setw(8) << setprecision(4) << a[i][j];
}
fin >> b[i];
cout << fixed << setw(8) << setprecision(4) << b[i] << endl;
}
Chasing_method(a, b, x, N_num);
cout << "追趕法求得方程組解為:" << endl;
for (int i = 0; i < N_num; i++)
{
cout<<"x["<<i<<"]=" << fixed << setw(8) << setprecision(4) << x[i] << endl;
}
}