【代码 -- 仓库布局】仓库布局

问题描述 ①

【代码 -- 仓库布局】仓库布局_第1张图片

代码
package Ring1270.pra.java01;
import java.util.Scanner;
/**
 * URL:
 * https://www.lanqiao.cn/courses/2786/learning/?id=67027
 */public class A_01warehouseLayout {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("n = ");
        int n = scanner.nextInt();
        System.out.print("m = ");
        int m = scanner.nextInt();
        Run run = new Run();
        System.out.println(run.sum(n, m));
    }
}
class Run{
    int sum(int n , int m) {
        int count = 0;
            for (int i = 1; i <= n; i++) {
                if ((i +1) % 3 != 0) {
                    for (int j = 1; j <= m; j++) {
                        if (j % 6 == 0) {
                            System.out.printf(" || ");
                        }else {
                            System.out.printf(" 货柜 ");
                            count++;
                        }
                    }
                    System.out.println();
                }else {
                    System.out.println();
                }
            }
        return count;
    }
}
运行截图

【代码 -- 仓库布局】仓库布局_第2张图片

问题描述②

【代码 -- 仓库布局】仓库布局_第3张图片

代码
package Ring1270.pra.java01;
import java.util.Scanner;
public class A_02warehouseLayout {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("n = ");
        int n = scanner.nextInt();
        System.out.print("m = ");
        int m = scanner.nextInt();
        Run02 run = new Run02();
        System.out.println(run.sum(n, m));
    }
}
class Run02{
    int sum(int n , int m) {
        int count = 0;
        if ((n-1) % 3 != 0) {
            for (int i = 1; i <= n; i++) {
                if ((i +1) % 3 != 0) {
                    for (int j = 1; j <= m; j++) {
                        if (j % 6 == 0) {
                            System.out.printf(" || ");
                        }else {
                            System.out.printf(" 货柜 ");
                            count++;
                        }
                    }
                    System.out.println();
                }else {
                    System.out.println();
                }
            }
        }else {
                for (int i = 1; i < n; i++) {
                    if ((i +1) % 3 != 0) {
                        for (int j = 1; j <= m; j++) {
                            if (j % 6 == 0) {
                                System.out.printf(" || ");
                            }else {
                                System.out.printf(" 货柜 ");
                                count++;
                            }
                        }
                        System.out.println();
                    }else {
                        System.out.println();
                    }
                }
            System.out.println();
            }
        return count;
    }
}
运行截图

【代码 -- 仓库布局】仓库布局_第4张图片

你可能感兴趣的:(java)