繁体   English   中英

Java数独样式程序

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM