[英]Sudoku style program in java
這是一個Sudoku樣式程序,僅在Sudoku中使用“ A,B,C”,並且在每一行或每一列中不能有兩個或多個相同的字母,但是在對角線上可以有兩個或多個相同的字母。 此“數獨游戲以3x3正方形播放”。 正方形中的每個框都編號為1-9(由於該框的位置),其中一個是左上方的框,兩個是上方的中間框...而九個是右邊緣框。 用戶將在游戲開始時輸入一行,其中將包含網格中字母的數量以及其位置,並且第一位數字是鎖定字母的數量。 鎖定字母是無法移動的字母。
這是我的代碼:
import java.util.Scanner; public class ABC { public static void main(String[] args) { Scanner S = new Scanner(System.in); System.out.println("Input:"); String IS = S.nextLine(); String[] SIS = IS.split(", "); int LOSIS = (SIS.length)-1; System.out.println(LOSIS); String[] location = new String[9]; // |_|_|_|_|_|_|_|_|_| for(int i = 1;i<=((SIS.length)-1)/2;i++){ System.out.println("In the loop"); int dummy = Integer.parseInt(SIS[i]); location[dummy] = SIS[i+1]; System.out.println(location[dummy]); i++; } String[] top = {location[0],location[1],location[2]}; String[] middle = {location[3],location[4],location[5]}; String[] bottom = {location[6],location[7],location[8]}; for(int i = 1; i>0; i++){ } } }
我清理了您的代碼。 Java變量以小寫字母開頭。 我將一些簡短的變量名更改為更長的,更具描述性的名稱。 我將空行放入代碼分組。 我不知道您是否研究過方法。 每個代碼組應該是一個單獨的方法。
import java.util.Scanner;
public class ABC {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input:");
String locationString = scanner.nextLine();
String[] locationDigits = locationString.split(", ");
int locationDigitsLength = (locationDigits.length) - 1;
System.out.println(locationDigitsLength);
String[] location = new String[9];
// |_|_|_|_|_|_|_|_|_|
for (int i = 1; i <= ((locationDigits.length) - 1) / 2; i++) {
System.out.println("In the loop");
int dummy = Integer.parseInt(locationDigits[i]);
location[dummy] = locationDigits[i + 1];
System.out.println(location[dummy]);
}
String[] top = { location[0], location[1], location[2] };
String[] middle = { location[3], location[4], location[5] };
String[] bottom = { location[6], location[7], location[8] };
for (int i = 1; i < location.length; i++) {
}
scanner.close();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.