C#基础第二天-作业答案-九九乘法表-打印星星

题一:九九乘法表的答案    

            //正三角
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}*{1}={2} ", j, i, i * j);
                }
                Console.WriteLine();
            }
            Console.ReadLine();

            //倒三角
            for (int i = 9; i >= 1; i--)
            {
                for (int j = i; j >= 1; j--)
                {

                    Console.Write("{0}*{1}={2} ", i, j, i * j);  //不换行
                }
                Console.WriteLine(); //换行
            }
            Console.ReadLine();  

            反倒三角
            string sd = string.Empty;
            for (int i = 9; i >= 1; i--)
            {
                for (int j = i; j >= 1; j--)
                {
                    string k = "  ";
                    if (j * i > 9)
                    {
                        k = " ";
                    }
                    Console.Write("{0}*{1}={2}{3}", j, i, i * j, k);
                }
                Console.WriteLine();
                sd += "       ";
                Console.Write(sd);
            }
            Console.ReadLine();

题二:

            //星星图1
            Console.WriteLine("请输入您想看到的星星行数");
            int num = Convert.ToInt32(Console.ReadLine());
            for (int hang = 1; hang <= num; hang++)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int kong = 1; kong <= num - hang; kong++)
                {
                    k += " ";
                }
                for (int xing = 1; xing <= hang; xing++)
                {
                    x += "* ";
                }
                Console.WriteLine(k + x + k);
            }
            Console.ReadLine();

            //星星图(倒三角星星)
            Console.WriteLine("请输入您想看到的星星行数");
            int num = Convert.ToInt32(Console.ReadLine());
            for (int hang = 1; hang <= num; hang++)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int kong = 1; kong <= hang - 1; kong++)
                {
                    k += " ";
                }
                for (int xing = 1; xing <= num - hang + 1; xing++)
                {
                    x += "* ";
                }
                Console.WriteLine(k + x + k);
            }
            Console.ReadLine();

            ////星星图四
            Console.WriteLine("请输入您想看到的星星行数");
            int num = Convert.ToInt32(Console.ReadLine());
            int gg = num * 2;
            for (int hang = 1; hang <= num; hang++)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int kong = 1; kong <= gg - 2 * hang; kong++)
                {
                    k += " ";
                }
                for (int xing = 1; xing <= hang; xing++)
                {
                    x += "* ";
                }
                Console.WriteLine(k + x);
            }
            Console.ReadLine();

            //星星图(倒三角*)
            Console.WriteLine("请输入您想看到的星星行数");
            int num = Convert.ToInt32(Console.ReadLine());
            int gg = num * 2;
            for (int hang = 1; hang <= num; hang++)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int kong = 1; kong <= 2 * (hang - 1); kong++)
                {
                    k += " ";
                }
                for (int xing = 1; xing <= num - hang + 1; xing++)
                {
                    x += "* ";
                }
                Console.WriteLine(k + x);
            }
            Console.ReadLine();

           //星星图(最终效果菱形)
            int a = int.Parse(Console.ReadLine());
            for (int i = 0; i <= a; i++)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int s = 0; s < a - i + 1; s++)
                {
                    k += " ";
                }
                for (int d = 0; d < 2 * i - 1; d++)
                {
                    x += "*";
                }
                Console.WriteLine(k + x + k);
            }
            for (int i = a - 1; i > 0; i--)
            {
                string k = String.Empty;
                string x = String.Empty;
                for (int s = 0; s < a - i + 1; s++)
                {
                    k += " ";
                }
                for (int d = 0; d < 2 * i - 1; d++)
                {
                    x += "*";
                }
                Console.WriteLine(k + x + k);
            }
            Console.ReadLine();
          //星星图(显示 图四效果/图五效果)最终显示图六效果

          for (int i = 1; i <= 4; i++)
            {
                for (int j = 1; j <= 4 - i; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine("");
            }
            for (int i = 4; i >= 1; i--)
            {
                for (int j = 1; j <= 4 - i; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
时间: 2024-10-20 20:08:49

C#基础第二天-作业答案-九九乘法表-打印星星的相关文章

C#基础第二天-作业-九九乘法表-打印星星

一.打印九九乘法表图形为下列效果图中的三角型的一种例: 图一效果1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40

python3 九九乘法表打印花式操作(然并卵)

# 九九乘法表# 方法一# for i in range(1, 10):# for j in range(1, i+1):# print('{}x{}={}\t'.format(i, j, i*j), end='')# print() # 方法二.# print ('\n'.join([' '.join(['%s*%s=%-2s' % (j,i,i*j) for j in range(1,i+1)]) for i in range(1,10)]))## 方法三.# print('\n'.join

Java -GUI开发九九乘法表

Java GUI开发九九乘法表 (1)实现目标: 利用java自带的awt包,基础控件开发一个九九乘法表,点击可以显示对应的乘法口诀. (2)控件选择: 点击--Button 显示--TextField (3)界面设计:总体设计布局 (4)主窗体编写 将程序在屏幕中央区显示 1 /*窗口居中显示*/ 2 int Win_width=fr.getWidth(); 3 int Win_Height=fr.getHeight(); 4 Toolkit kit = Toolkit.getDefaultT

九九乘法表的实现--JAVA基础

JAVA算法实现:输出九九乘法表 Jiujiu.java: package com.qkys.www; public class Jiujiu { public static void main(String[] args){ for(int i=1;i<=9;i++){ for (int j=1; j<=i ;j++) { System.out.print(j+"x"+i+"="+j*i+" "); } System.out.pri

JSP基础——分别使用表达式和脚本方式打印九九乘法表

最近在学习慕课网的课程<java遇见HTML--JSP篇>,简单做些记录. 课程网址为:http://www.imooc.com/learn/166 任务描述:分别使用表达式和脚本方式打印九九乘法表 代码如下: <%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%> <% String path =

作业6-凯撒编码、GDP格式化输出、九九乘法表

1.凯撒密码的编码 运行结果: 2.国家名称 GDP总量(人民币亿元)中国 ¥765873.4375澳大利亚 ¥ 78312.4375(国家名称左对齐,数字右对齐,千分位,2位小数) 运行结果: 3.九九乘法表 运行结果:

作业 - 九九乘法表

1 //实现梯形九九乘法表的效果 2 import Foundation 3 4 for var a in 1...9{ 5 for var b in 1...a{ 6 print("\(b)*\(a)=\(a*b) ",terminator:"\t") 7 } 8 print() 9 }

九九乘法表及其扩展

九九乘法表的程序如下: #define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> int main() { int i = 0; int j = 0; for (i = 1; i <= 9; i++) { for (j = 1; j <= i; j++) { printf("%d*%d=%2d  ", i, j, i*j); } printf("\n&quo

利用js的for循环实现一个简单的“九九乘法表”

For循环九九乘法表 for循环是javascript中一种常用的循环语句,可以很好的解决在程序中需要重复执行某些语句,利用for循环实现简单的“九九乘法表”的效果: 让循环从小到大,依次排序,并计算每次的结果,并用 table 使之排列出来. <script type="text/javascript"> document.write('<table border="1">'); //以表格规格打印 for(var i=1;i<=9;