1. If there is Tang poetry
Hoe wo Day Copse
Sweat wo xia tu
Who knows how to dish Chinese
The grain is hard
This poem is required to be exported in accordance with the ancient prose style, the output format is as follows:
Tablets who sweat hoe
Grain-known drip wo
Pan Wo Day
Sinzhong down when
The bitter meal of the earth Noon
importjava.util.*;
public class Test {
public static void Main (string[] args) {
String[][] s={{"hoe", "Wo", "Day", "when", "noon"},{"Khan", "drip", "wo", "Xia", "tu"},{"who", "Know", "dish", "medium", "meal"},{"grain", "grain", "all", "Xin", "Bitter"};
String[][] R=new string[5][4];
int y=3;
for (int i=0;i<5;i++)
{
for (int j=0;j<5;j++)
{
R[J][Y]=S[I][J];
}
y--;
if (y<0)
{
Break
}
}
for (int i=0;i<5;i++)
{
for (int j=0;j<4;j++)
{
System.out.print (R[i][j]);
}
System.out.print ("\ n");
}
}
}
2. To lay mines for minesweeper games, minesweeper can be represented by a two-dimensional int array. If a location is a mine, the position is represented by a number-1,
If the location is not a mine, it is temporarily represented by the number 0.
The program completes the operation of random mines in the two-dimensional array, and the program reads 3 parameters: Number of rows (r) of the Bray panel, number of columns (c), number of mines laid out (N),
And to meet the 0<n<r*c*0.75 (that is, the maximum density of the laid-off mines is 75%), the program runs after the N-mines are randomly placed in a two-dimensional array of r*c
importjava.util.*;
public class Test {
public static void Main (string[] args) {
Scanner rcn=new Scanner (system.in);
Scanner ccn=new Scanner (system.in);
Scanner ncn=new Scanner (system.in);
System.out.print ("\ T" + "Welcome to Minesweeper Game!") "+" \ n ");
System.out.print ("Number of input lines:");
int R=integer.parseint (Rcn.nextline ());
System.out.print ("\ n" + "input number of columns:");
int C=integer.parseint (Ccn.nextline ());
int n;
Do
{
System.out.print ("\ n" + "Enter the number of mines to be cloth (the number of thunder can not exceed the total number of%75):");
N=integer.parseint (Ncn.nextline ());
}while (N<0&&N>R*C*3/4);
Int[][] S=new Int[r][c];
int th=1;
for (int i=0;i<s.length;i++)
{
for (int j=0;j<s[0].length;j++)
{
if (th<=r*c)
{
s[i][j]=th;
th++;
}
}
}
Int[] Tg=new Int[n];
for (int i=0;i<n;i++)
{
tg[i]=0;
}
Random sn=new random ();
for (int i=0;i<n;)
{
int tgh;
tgh= (int) (sn.nextdouble () *r*c) +1;
Boolean ty=flase;
for (int j=0;j<=i;j++)
{
if (Tgh==tg[j])
{
Ty=true;
Break
}
}
if (Ty)
{
Continue
}
else if (tg[i]==0)
{
Tg[i]=tgh;
i++;
}
}
/*for (int i=0;i<n;i++)
{
System.out.print (tg[i]+ "\ t");
}*/
for (int q=0;q<s.length;q++)
{
for (int j=0;j<s[0].length;j++)
{
Boolean tu=true;
for (int i=0;i<n;i++)
{
if (S[q][j]==tg[i])
{
S[q][j]=-1;
Tu=flase;
}
}
if (TU)
{
s[q][j]=0;
}
}
}
for (int q=0;q<s.length;q++)
{
for (int j=0;j<s[0].length;j++)
{
System.out.print (s[q][j]+ "\ t");
}
System.out.print ("\ n");
}
}
}
The above code is my personal writing, I think I can welcome the adoption of friends, reproduced please indicate the source.
Java topic Sharing