JAVA语言 用嵌套的循环语句,分别边写程序打印下列图案。
Pattern1112123123412345123456Pattern2123456123451234123121Parrern31213214321543216543...
Pattern1
1
12
123
1234
12345
123456
Pattern2
123456
12345
1234
123
12
1
Parrern3
1
21
321
4321
54321
654321
Pattern4
123456
12345
1234
123
12
1
就是这个四个图案。。纠结死我了。 展开
1
12
123
1234
12345
123456
Pattern2
123456
12345
1234
123
12
1
Parrern3
1
21
321
4321
54321
654321
Pattern4
123456
12345
1234
123
12
1
就是这个四个图案。。纠结死我了。 展开
3个回答
展开全部
Pattern1:
public class Pattern1{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1;j<=i;j++)
System.out.print(j);
System.out.println();
}
}
}
Pattern2:
public class Pattern2{
public static void main(String[] args) {
for(int i = 6;i>=1;i--){
for(int j = 1;j<=i;j++)
System.out.print(j);
System.out.println();
}
}
}
Pattern3 :
public class Pattern3{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1; j<=(6-i);j++)
System.out.print(" ");
for(int j = i;j>=1;j--)
System.out.print(j);
System.out.println();
}
}
}
Pattern4:
public class Pattern4{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1; j<=(i-1);j++)
System.out.print(" ");
for(int j = 1;j<=(7-i);j++)
System.out.print(j);
System.out.println();
}
}
}
我都测试过了。。。。希望能帮到你。。。。
public class Pattern1{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1;j<=i;j++)
System.out.print(j);
System.out.println();
}
}
}
Pattern2:
public class Pattern2{
public static void main(String[] args) {
for(int i = 6;i>=1;i--){
for(int j = 1;j<=i;j++)
System.out.print(j);
System.out.println();
}
}
}
Pattern3 :
public class Pattern3{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1; j<=(6-i);j++)
System.out.print(" ");
for(int j = i;j>=1;j--)
System.out.print(j);
System.out.println();
}
}
}
Pattern4:
public class Pattern4{
public static void main(String[] args) {
for(int i = 1;i<=6;i++){
for(int j = 1; j<=(i-1);j++)
System.out.print(" ");
for(int j = 1;j<=(7-i);j++)
System.out.print(j);
System.out.println();
}
}
}
我都测试过了。。。。希望能帮到你。。。。
展开全部
public class Test {
static void print(int index, int begin, int end){//每行从第index格开始打印,从begin到end
for (int i = 0; i < index; i++) {
System.out.print(" ");
}
if(begin < end)for (int i = begin; i <= end; i++) {
System.out.print(i);
}
else for (int i = begin; i >= end; i--) {
System.out.print(i);
}
System.out.println();
}
static void print1(){
for (int i = 1; i <= 6; i++) {
print(0, 1, i);//每行从1开始打印
}
System.out.println("\n\n");
}
static void print2(){
for (int i = 1; i <= 6; i++) {
print(0, 1, 7-i);//每行从1开始打印
}
System.out.println("\n\n");
}
static void print3(){
for (int i = 1; i <= 6; i++) {
print(6-i, i, 1);//每行从i开始打印i个数字
}
System.out.println("\n\n");
}
static void print4(){
for (int i = 1; i <= 6; i++) {
print(i-1, 1, 7-i);//每行从i开始打印i个数字
}
System.out.println("\n\n");
}
public static void main(String[] args) {
print1();
print2();
print3();
print4();
}
}
static void print(int index, int begin, int end){//每行从第index格开始打印,从begin到end
for (int i = 0; i < index; i++) {
System.out.print(" ");
}
if(begin < end)for (int i = begin; i <= end; i++) {
System.out.print(i);
}
else for (int i = begin; i >= end; i--) {
System.out.print(i);
}
System.out.println();
}
static void print1(){
for (int i = 1; i <= 6; i++) {
print(0, 1, i);//每行从1开始打印
}
System.out.println("\n\n");
}
static void print2(){
for (int i = 1; i <= 6; i++) {
print(0, 1, 7-i);//每行从1开始打印
}
System.out.println("\n\n");
}
static void print3(){
for (int i = 1; i <= 6; i++) {
print(6-i, i, 1);//每行从i开始打印i个数字
}
System.out.println("\n\n");
}
static void print4(){
for (int i = 1; i <= 6; i++) {
print(i-1, 1, 7-i);//每行从i开始打印i个数字
}
System.out.println("\n\n");
}
public static void main(String[] args) {
print1();
print2();
print3();
print4();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我累个去,我学过一点点的ASP,但是弄不出来!头大!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询