- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
enter image description here导入java.util.Scanner;
public class EnglishCheckers {
// Global constants
public static final int RED = 1;
public static final int BLUE = -1;
public static final int EMPTY = 0;
public static final int SIZE = 8;
// You can ignore these constants
public static final int MARK = 3;
public static EnglishCheckersGUI grid;
public static Scanner getPlayerFullMoveScanner = null;
public static Scanner getStrategyScanner = null;
public static final int RANDOM = 1;
public static final int DEFENSIVE = 2;
public static final int SIDES = 3;
public static final int CUSTOM = 4;
public static void main(String[] args) {
// ******** Don't delete *********
// CREATE THE GRAPHICAL GRID
grid = new EnglishCheckersGUI(SIZE);
// *******************************
//showBoard(example);
//printMatrix(example);
//interactivePlay();
//twoPlayers();
/* ******** Don't delete ********* */
if (getPlayerFullMoveScanner != null){
getPlayerFullMoveScanner.close();
}
if (getStrategyScanner != null){
getStrategyScanner.close();
}
/* ******************************* */
}
public static int[][] createBoard() {
int[][] board = null;
board=new int[8][8]; // defines the new length of the array
for (int j=0; j<8; j=j+1)
{
for (int m=0; m<8; m=m+1) // these two "for" loops will set the value of each square of the board according to the instructions regarding it's location.
{
if (j==0|j==2)
{
if (m%2==0)
board[j][m]=1;
else
board[j][m]=0;
}
if (j==1)
{
if (m%2!=0)
board[j][m]=1;
else
board[j][m]=0;
}
if (j>2&j<5)
board[j][m]=0;
if (j==5|j==7)
{
if (m%2!=0)
board[j][m]=-1;
else
board[j][m]=0;
}
if (j==6)
{
if (m%2==0)
board[j][m]=-1;
else
board[j][m]=0;
}
}
}
return board;
}
public static int howManyDiscs (int[][] board, int player){ // this function will return the number of discs a player has on the board
int positive=0;
int negative=0;
for (int i=0; i<8; i=i+1)
{
for (int j=0; j<8; j=j+1)
{
if (board[i][j]>0) positive=positive+1;
if (board[i][j]<0) negative=negative+1;
}
}
if (player>0) return positive;
else return negative;
}
public static int[][] playerDiscs(int[][] board, int player) {
int[][] positions = null;
if (howManyDiscs(board,player)>0)
{
positions=new int[howManyDiscs(board,player)][2]; // defines the new length of the array
int line=0;
for (int i=0; i<8; i=i+1)
{
for (int j=0; j<8; j=j+1)
{
if (player>0&&board[i][j]>0) // will update the array if the player is 1
{
positions[line][0]=i;
positions[line][1]=j;
line=line+1;
}
if (player<0&&board[i][j]<0) // will update the array if the player is (-1)
{
positions[line][0]=i;
positions[line][1]=j;
line=line+1;
}
}
}
}
return positions;
}
public static boolean isBasicMoveValid(int[][] board, int player, int fromRow, int fromCol, int toRow, int toCol) {
boolean ans = false;
if (fromRow>=0&&fromRow<8&&fromCol>=0&&fromCol<8&&toRow>=0&&toRow<8&&toCol>=0&&toCol<8) // makes sure the coordinates are legal
{
if (board[fromRow][fromCol]==player|board[fromRow][fromCol]==player*2) // checks if a disc of the player exists in the origin square
{
if(board[toRow][toCol]==0) // checks if the destination square is legal
{
if (toCol==fromCol+1||toCol==fromCol-1) // checks if the destination column is legal
{
if (toRow==fromRow+1&&player!=-1) // makes sure the move is legal for a player that isn't (-1)
{
ans=true;
}
if (toRow==fromRow-1&&player!=1) // makes sure the move is legal for a player that isn't 1
{
ans=true;
}
}
}
}
}
return ans;
}
public static int[][] getAllBasicMoves(int[][] board, int player) {
int[][] moves = null;
int line=0;
for (int i=0; i<8; i=i+1)
{
for (int j=0; j<8; j=j+1) // these 2 "for" loops will add 1 to the counter "line" for each legal move a square has
{
if (isBasicMoveValid(board,player,i,j,i+1,j+1)) line=line+1;
if (isBasicMoveValid(board,player,i,j,i+1,j-1)) line=line+1;
if (isBasicMoveValid(board,player,i,j,i-1,j+1)) line=line+1;
if (isBasicMoveValid(board,player,i,j,i-1,j-1)) line=line+1;
}
}
moves=new int[line][4]; // creating the length of the output array according to the amount of possibilities found
line=0;
for (int i=0; i<8; i=i+1)
{
for (int j=0; j<8; j=j+1) // the if's below will insert every move that exists for each square to the array
{
if (isBasicMoveValid(board,player,i,j,i+1,j+1))
{
moves[line][0]=i;
moves[line][1]=j;
moves[line][2]=i+1;
moves[line][3]=j+1;
line=line+1;
}
if (isBasicMoveValid(board,player,i,j,i+1,j-1))
{
moves[line][0]=i;
moves[line][1]=j;
moves[line][2]=i+1;
moves[line][3]=j-1;
line=line+1;
}
if (isBasicMoveValid(board,player,i,j,i-1,j+1))
{
moves[line][0]=i;
moves[line][1]=j;
moves[line][2]=i-1;
moves[line][3]=j+1;
line=line+1;
}
if (isBasicMoveValid(board,player,i,j,i-1,j-1))
{
moves[line][0]=i;
moves[line][1]=j;
moves[line][2]=i-1;
moves[line][3]=j-1;
line=line+1;
}
}
}
return moves;
}
public static boolean isBasicJumpValid(int[][] board, int player, int fromRow, int fromCol, int toRow, int toCol) {
boolean ans = false;
if (fromRow>=0&&fromRow<8&&fromCol>=0&&fromCol<8&&toRow>=0&&toRow<8&&toCol>=0&&toCol<8) // makes sure the coordinates are legal
{
if (board[fromRow][fromCol]==player|board[fromRow][fromCol]==player*2) // checks if a disc of the player exists in the origin square
{
if(board[toRow][toCol]==0) // checks if the destination square is legal
{
if (toRow==fromRow+2)
{
if (toCol==fromCol+2)
{
if (player==1|player==2)
{
if (board[fromRow+1][fromCol+1]<0)
ans=true;
}
if (player==-2)
{
if (board[fromRow+1][fromCol+1]>0)
ans=true;
}
}
if (toCol==fromCol-2)
{
if (player==1|player==2)
{
if (board[fromRow+1][fromCol-1]<0)
ans=true;
}
if (player==-2)
{
if (board[fromRow+1][fromCol-1]>0)
ans=true;
}
}
}
if (toRow==fromRow-2)
{
if (toCol==fromCol+2)
{
if (player==-1|player==-2)
{
if (board[fromRow-1][fromCol+1]>0)
ans=true;
}
if (player==2)
{
if (board[fromRow-1][fromCol+1]<0)
ans=true;
}
}
if (toCol==fromCol-2)
{
if (player==-1|player==-2)
{
if (board[fromRow-1][fromCol-1]>0)
ans=true;
}
if (player==2)
{
if (board[fromRow-1][fromCol-1]<0)
ans=true;
}
}
}
}
}
}
return ans;
}
public static int [][] getRestrictedBasicJumps(int[][] board, int player, int row, int col) {
int[][] moves = null;
int line=0;
for (int i=row-2; i<=row+2; i=i+2)
{
for (int j=col-2; j<=col+2; j=j+2) // these 2 "for" loops will add 1 to the counter "line" for each legal move a square has
{
if (isBasicJumpValid(board,player,row,col,i,j)) line=line+1;
}
}
moves=new int[line][4]; // creating the length of the output array according to the amount of possibilities found
line=0;
for (int i=row-2; i<=row+2; i=i+2)
{
for (int j=col-2; j<=col+2; j=j+2)
{
if (isBasicJumpValid(board,player,row,col,i,j)) // will insert every possible jump to the array
{
moves[line][0]=row;
moves[line][1]=col;
moves[line][2]=i;
moves[line][3]=j;
line=line+1;
}
}
}
return moves;
}
public static int[][] getAllBasicJumps(int[][] board, int player) {
int [][] moves = null;
int [][] discs = playerDiscs(board,player); // this array holds a list of the discs the player has on the board currently
int counter=0;
for (int i=0; i<discs.length; i=i+1) // will add each disc's amount of possible moves to the counter
counter=counter+getRestrictedBasicJumps(board,player,discs[i][0],discs[i][1]).length;
moves=new int[counter][4]; // defining the array's size according to the sum of all discs possible jumps
int line=0;
for (int a=0; a<discs.length; a=a+1)
{
int [][] jumps = getRestrictedBasicJumps(board,player,discs[a][0],discs[a][1]); // creates the array "jumps" that holds the possible jumps for the current "for" disc
for (int i=0; i<jumps.length; i=i+1) // will insert each line of the jumps array to the moves array
{
moves[line][0]=jumps[i][0];
moves[line][1]=jumps[i][1];
moves[line][2]=jumps[i][2];
moves[line][3]=jumps[i][3];
line=line+1;
}
}
return moves;
}
public static boolean canJump(int[][] board, int player) {
boolean ans = false;
if (getAllBasicJumps(board,player).length>0) ans=true;
return ans;
}
public static boolean isMoveValid(int[][] board, int player, int fromRow, int fromCol, int toRow, int toCol) {
boolean ans = false;
if (isBasicJumpValid(board,player,fromRow,fromCol,toRow,toCol))
ans=true;
else
if (isBasicMoveValid (board,player,fromRow,fromCol,toRow,toCol))
ans=true;
return ans;
}
public static boolean hasValidMoves(int[][] board, int player) {
boolean ans = false;
if (getAllBasicMoves(board,player).length>0) ans=true;
if (canJump(board,player)) ans=true;
return ans;
}
public static int[][] playMove(int[][] board, int player, int fromRow, int fromCol, int toRow, int toCol) {
if (isBasicJumpValid(board,player,fromRow,fromCol,toRow,toCol)) // in case it's a jump- will replace the eaten player with 0
{
if (fromRow>toRow)
{
if (fromCol>toCol) board[fromRow-1][fromCol-1]=0;
else board[fromRow-1][fromCol+1]=0;
}
else
{
if (fromCol>toCol) board[fromRow+1][fromCol-1]=0;
else board[fromRow+1][fromCol+1]=0;
}
}
if (player==1&toRow==7)
{
board[toRow][toCol]=2;
board[fromRow][fromCol]=0;
}
else
{
if (player==-1&toRow==0)
{
board[toRow][toCol]=-2;
board[fromRow][fromCol]=0;
}
else
{
board[toRow][toCol]=player;
board[fromRow][fromCol]=0;
}
}
return board;
}
public static boolean gameOver(int[][] board, int player) {
boolean ans = false;
if (!hasValidMoves(board,player)) ans=true;
if (playerDiscs(board,1)==null | playerDiscs(board,-1)==null) ans=true;
return ans;
}
public static int findTheLeader(int[][] board) {
int ans = 0;
int player1=0, player2=0;
for (int i=0; i<8; i=i+1)
{
for (int j=0; j<8; j=j+1)
{
if (board[i][j]==1) player1=player1+1;
if (board[i][j]==2) player1=player1+2;
if (board[i][j]==-1) player1=player2+1;
if (board[i][j]==-2) player1=player2+2;
}
}
if (player1>player2)
ans=1;
else
if (player2>player1)
ans=-1;
else
ans=0;
return ans;
}
public static int[][] randomPlayer(int[][] board, int player) {
if (hasValidMoves(board,player))
{
if (getAllBasicMoves(board,player).length>0 && isMoveValid(board,player,getAllBasicMoves(board,player)[0][0],getAllBasicMoves(board,player)[0][1],getAllBasicMoves(board,player)[0][2],getAllBasicMoves(board,player)[0][3]))
board=playMove(board,player,getAllBasicMoves(board,player)[0][0],getAllBasicMoves(board,player)[0][1],getAllBasicMoves(board,player)[0][2],getAllBasicMoves(board,player)[0][3]);
else
if (getAllBasicJumps(board,player).length>0 && isMoveValid(board,player,getAllBasicJumps(board,player)[0][0],getAllBasicJumps(board,player)[0][1],getAllBasicJumps(board,player)[0][2],getAllBasicJumps(board,player)[0][3]))
board=playMove(board,player,getAllBasicJumps(board,player)[0][0],getAllBasicJumps(board,player)[0][1],getAllBasicJumps(board,player)[0][2],getAllBasicJumps(board,player)[0][3]);
}
return board;
}
public static int[][] defensivePlayer(int[][] board, int player) {
if (hasValidMoves(board,player))
{
if (canJump(board,player))
board=playMove(board,player,getAllBasicJumps(board,player)[0][0],getAllBasicJumps(board,player)[0][1],getAllBasicJumps(board,player)[0][2],getAllBasicJumps(board,player)[0][3]);
else
{
boolean goodMove=false;
int i=0;
int [][] arr=board;
while (i<getAllBasicMoves(board,player).length && !goodMove)
{
arr=playMove(board,player,getAllBasicMoves(board,player)[i][0],getAllBasicMoves(board,player)[i][1],getAllBasicMoves(board,player)[i][2],getAllBasicMoves(board,player)[i][3]);
if (!canJump(arr,-player))
goodMove=true;
i=i+1;
}
board=arr;
}
}
return board;
}
public static int[][] sidesPlayer(int[][] board, int player) {
if (hasValidMoves(board,player))
{
if (canJump(board,player))
board=playMove(board,player,getAllBasicJumps(board,player)[0][0],getAllBasicJumps(board,player)[0][1],getAllBasicJumps(board,player)[0][2],getAllBasicJumps(board,player)[0][3]);
else
{
if (getAllBasicMoves(board,player).length>1)
{
int bestMove=0, minHefresh=7;
for (int i=1; i<getAllBasicMoves(board,player).length; i=i+1)
{
if (Math.abs(0-getAllBasicMoves(board,player)[i][3])<minHefresh)
{
bestMove=i;
minHefresh=Math.abs(0-getAllBasicMoves(board,player)[i][3]);
}
if (Math.abs(0-getAllBasicMoves(board,player)[i-1][3])<minHefresh)
{
bestMove=i-1;
minHefresh=Math.abs(0-getAllBasicMoves(board,player)[i-1][3]);
}
if (Math.abs(7-getAllBasicMoves(board,player)[i][3])<minHefresh)
{
bestMove=i;
minHefresh=Math.abs(7-getAllBasicMoves(board,player)[i][3]);
}
if (Math.abs(7-getAllBasicMoves(board,player)[i-1][3])<minHefresh)
{
bestMove=i-1;
minHefresh=Math.abs(7-getAllBasicMoves(board,player)[i-1][3]);
}
}
board=playMove(board,player,getAllBasicMoves(board,player)[bestMove][0],getAllBasicMoves(board,player)[bestMove][1],getAllBasicMoves(board,player)[bestMove][2],getAllBasicMoves(board,player)[bestMove][3]);
}
else
board=playMove(board,player,getAllBasicMoves(board,player)[0][0],getAllBasicMoves(board,player)[0][1],getAllBasicMoves(board,player)[0][2],getAllBasicMoves(board,player)[0][3]);
}
}
return board;
}
//******************************************************************************//
/* ---------------------------------------------------------- *
* Play an interactive game between the computer and you *
* ---------------------------------------------------------- */
public static void interactivePlay() {
int[][] board = createBoard();
showBoard(board);
System.out.println("Welcome to the interactive Checkers Game !");
int strategy = getStrategyChoice();
System.out.println("You are the first player (RED discs)");
boolean oppGameOver = false;
while (!gameOver(board, RED) && !oppGameOver) {
board = getPlayerFullMove(board, RED);
oppGameOver = gameOver(board, BLUE);
if (!oppGameOver) {
EnglishCheckersGUI.sleep(200);
board = getStrategyFullMove(board, BLUE, strategy);
}
}
int winner = 0;
if (playerDiscs(board, RED).length == 0 | playerDiscs(board, BLUE).length == 0){
winner = findTheLeader(board);
}
if (winner == RED) {
System.out.println();
System.out.println("\t *************************");
System.out.println("\t * You are the winner !! *");
System.out.println("\t *************************");
}
else if (winner == BLUE) {
System.out.println("\n======= You lost :( =======");
}
else
System.out.println("\n======= DRAW =======");
}
/* --------------------------------------------------------- *
* A game between two players *
* --------------------------------------------------------- */
public static void twoPlayers() {
int[][] board = createBoard();
showBoard(board);
System.out.println("Welcome to the 2-player Checkers Game !");
boolean oppGameOver = false;
while (!gameOver(board, RED) & !oppGameOver) {
System.out.println("\nRED's turn");
board = getPlayerFullMove(board, RED);
oppGameOver = gameOver(board, BLUE);
if (!oppGameOver) {
System.out.println("\nBLUE's turn");
board = getPlayerFullMove(board, BLUE);
}
}
int winner = 0;
if (playerDiscs(board, RED).length == 0 | playerDiscs(board, BLUE).length == 0)
winner = findTheLeader(board);
System.out.println();
System.out.println("\t ************************************");
if (winner == RED)
System.out.println("\t * The red player is the winner !! *");
else if (winner == BLUE)
System.out.println("\t * The blue player is the winner !! *");
else
System.out.println("\t * DRAW !! *");
System.out.println("\t ************************************");
}
/* --------------------------------------------------------- *
* Get a complete (possibly a sequence of jumps) move *
* from a human player. *
* --------------------------------------------------------- */
public static int[][] getPlayerFullMove(int[][] board, int player) {
// Get first move/jump
int fromRow = -1, fromCol = -1, toRow = -1, toCol = -1;
boolean jumpingMove = canJump(board, player);
boolean badMove = true;
getPlayerFullMoveScanner = new Scanner(System.in);//I've modified it
while (badMove) {
if (player == 1){
System.out.println("Red, Please play:");
} else {
System.out.println("Blue, Please play:");
}
fromRow = getPlayerFullMoveScanner.nextInt();
fromCol = getPlayerFullMoveScanner.nextInt();
int[][] moves = jumpingMove ? getAllBasicJumps(board, player) : getAllBasicMoves(board, player);
markPossibleMoves(board, moves, fromRow, fromCol, MARK);
toRow = getPlayerFullMoveScanner.nextInt();
toCol = getPlayerFullMoveScanner.nextInt();
markPossibleMoves(board, moves, fromRow, fromCol, EMPTY);
badMove = !isMoveValid(board, player, fromRow, fromCol, toRow, toCol);
if (badMove)
System.out.println("\nThis is an illegal move");
}
// Apply move/jump
board = playMove(board, player, fromRow, fromCol, toRow, toCol);
showBoard(board);
// Get extra jumps
if (jumpingMove) {
boolean longMove = (getRestrictedBasicJumps(board, player, toRow, toCol).length > 0);
while (longMove) {
fromRow = toRow;
fromCol = toCol;
int[][] moves = getRestrictedBasicJumps(board, player, fromRow, fromCol);
boolean badExtraMove = true;
while (badExtraMove) {
markPossibleMoves(board, moves, fromRow, fromCol, MARK);
System.out.println("Continue jump:");
toRow = getPlayerFullMoveScanner.nextInt();
toCol = getPlayerFullMoveScanner.nextInt();
markPossibleMoves(board, moves, fromRow, fromCol, EMPTY);
badExtraMove = !isMoveValid(board, player, fromRow, fromCol, toRow, toCol);
if (badExtraMove)
System.out.println("\nThis is an illegal jump destination :(");
}
// Apply extra jump
board = playMove(board, player, fromRow, fromCol, toRow, toCol);
showBoard(board);
longMove = (getRestrictedBasicJumps(board, player, toRow, toCol).length > 0);
}
}
return board;
}
/* --------------------------------------------------------- *
* Get a complete (possibly a sequence of jumps) move *
* from a strategy. *
* --------------------------------------------------------- */
public static int[][] getStrategyFullMove(int[][] board, int player, int strategy) {
if (strategy == RANDOM)
board = randomPlayer(board, player);
else if (strategy == DEFENSIVE)
board = defensivePlayer(board, player);
else if (strategy == SIDES)
board = sidesPlayer(board, player);
showBoard(board);
return board;
}
/* --------------------------------------------------------- *
* Get a strategy choice before the game. *
* --------------------------------------------------------- */
public static int getStrategyChoice() {
int strategy = -1;
getStrategyScanner = new Scanner(System.in);
System.out.println("Choose the strategy of your opponent:" +
"\n\t(" + RANDOM + ") - Random player" +
"\n\t(" + DEFENSIVE + ") - Defensive player" +
"\n\t(" + SIDES + ") - To-the-Sides player player");
while (strategy != RANDOM & strategy != DEFENSIVE
& strategy != SIDES) {
strategy=getStrategyScanner.nextInt();
}
return strategy;
}
/* --------------------------------------- *
* Print the possible moves *
* --------------------------------------- */
public static void printMoves(int[][] possibleMoves) {
for (int i = 0; i < 4; i = i+1) {
for (int j = 0; j < possibleMoves.length; j = j+1)
System.out.print(" " + possibleMoves[j][i]);
System.out.println();
}
}
/* --------------------------------------- *
* Mark/unmark the possible moves *
* --------------------------------------- */
public static void markPossibleMoves(int[][] board, int[][] moves, int fromRow, int fromColumn, int value) {
for (int i = 0; i < moves.length; i = i+1)
if (moves[i][0] == fromRow & moves[i][1] == fromColumn)
board[moves[i][2]][moves[i][3]] = value;
showBoard(board);
}
/* --------------------------------------------------------------------------- *
* Shows the board in a graphic window *
* you can use it without understanding how it works. *
* --------------------------------------------------------------------------- */
public static void showBoard(int[][] board) {
grid.showBoard(board);
}
/* --------------------------------------------------------------------------- *
* Print the board *
* you can use it without understanding how it works. *
* --------------------------------------------------------------------------- */
public static void printMatrix(int[][] matrix){
for (int i = matrix.length-1; i >= 0; i = i-1){
for (int j = 0; j < matrix.length; j = j+1){
System.out.format("%4d", matrix[i][j]);
}
System.out.println();
}
}
}
嗨。刚刚开始编码,安装了 ide intellij 但我无法运行代码。非常感谢!
如您所见,运行命令的绿色箭头已禁用。此外,当我尝试从工具栏的运行菜单运行时,它只是说编辑配置。
最佳答案
只需将光标置于“主”方法行,然后按右键并选择运行。
关于java - 无法运行代码,intellij run arrow是 'grey',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43376795/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!