java中的数独风格程序

时间:2016-03-06 02:50:20

标签: java

这是一个仅使用' 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++){
			
		}
		

	}

}
&#13;
&#13;
&#13; 我能够获得用户的输入并在我的数组中添加锁定的alphbets,但我不知道如何填写其他所有内容。

1 个答案:

答案 0 :(得分:0)

我清理了你的代码。 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();
    }

}
相关问题