Java程序以正弦波模式打印数字的平方

编写一个 Java 程序,使用 for 循环以正弦波模式打印数字的平方。

package Shapes4;
import java.util.Scanner;

public class SquareSineWaveNum1 {

	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Numbers in Sine Wave Pat Side = ");
		int rows = sc.nextInt();
		
		System.out.println("The Square of Numbers in Sine Wave Pattern");
		
		for (int i = 0; i < rows; i++ ) 
		{
			for (int j = 0; j < rows; j++ ) 
			{
				if(j % 2 == 0)
				{
					System.out.print((rows * j) + i + 1 + " ");
				}
				else
				{
					System.out.print((rows * (j + 1)) - i + " ");
				}	
			}
			System.out.println();
		}
	}
}
Java Program to Print Square of Numbers in Sine Wave Pattern

Java 程序 使用 while 循环以正弦波格式打印数字的平方模式。

package Shapes4;

import java.util.Scanner;

public class SquareSineWaveNum2 {

	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Numbers in Sine Wave Pat Side = ");
		int rows = sc.nextInt();
		
		System.out.println("The Square of Numbers in Sine Wave Pattern");
		int i, j;
		i = 0;
		
		while(i < rows) 
		{
			j = 0; 
			while(j < rows) 
			{
				if(j % 2 == 0)
				{
					System.out.print((rows * j) + i + 1 + " ");
				}
				else
				{
					System.out.print((rows * (j + 1)) - i + " ");
				}	
				j++;
			}
			System.out.println();
			i++;
		}
	}
}
Enter Square Numbers in Sine Wave Pat Side = 13
The Square of Numbers in Sine Wave Pattern
1 26 27 52 53 78 79 104 105 130 131 156 157 
2 25 28 51 54 77 80 103 106 129 132 155 158 
3 24 29 50 55 76 81 102 107 128 133 154 159 
4 23 30 49 56 75 82 101 108 127 134 153 160 
5 22 31 48 57 74 83 100 109 126 135 152 161 
6 21 32 47 58 73 84 99 110 125 136 151 162 
7 20 33 46 59 72 85 98 111 124 137 150 163 
8 19 34 45 60 71 86 97 112 123 138 149 164 
9 18 35 44 61 70 87 96 113 122 139 148 165 
10 17 36 43 62 69 88 95 114 121 140 147 166 
11 16 37 42 63 68 89 94 115 120 141 146 167 
12 15 38 41 64 67 90 93 116 119 142 145 168 
13 14 39 40 65 66 91 92 117 118 143 144 169