格式操纵符输出九九乘法表

c++用格式操纵符输出九九乘法表
提示:

 for(int i=1;i<=9;i++)
    {
......
        for(int j=1;j<=x;j++)
......
把x改成i是左下三角形的99乘法表,把x改为9是完整得99乘法表。

另外我还提供多了一种方法!

缺点是我感觉对齐很生硬!



#include<iostream>
#include<iomanip>
using namespace std;


void main()
{
	system("Title 格式操纵符输出九九乘法表");
	system("color 2E");
	cout<<"格式操纵符输出九九乘法表"<<endl;
	cout<<"↓Powered by Moshow魔手↓"<<endl<<endl;
//方法一:
	//cout<<" ";
	//for(int m=1;m<=9;m++)
	//{cout<<setw(7)<<setfill(' ')<<m;}
	//cout<<endl;
	//for(int i=1;i<=9;i++)
	//{	cout<<i;
	//	for(int j=1;j<=i;j++)
	//	{
	//		cout<<setw(2)<<setfill(' ')<<i<<"x"<<j<<"=";
	//		cout<<setw(2)<<setfill(' ')<<i*j;
	//	}
	//	cout<<endl;
	//}
//方法二:
    for(int i=1;i<=9;i++)
	{cout<<setw(7)<<i;}
    cout<<endl;
    for(int i=1;i<=9;i++)
    {
        cout<<i<<setw(2);
        for(int j=1;j<=i;j++)
        {
            if(i*j<10&&j!=1) cout<<setw(2);
            cout<<i<<"x"<<j<<"="<<i*j<<" ";
        }
        cout<<endl;
    }
	system("Pause");
}


已标记关键词 清除标记
相关推荐
<p>   </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 学习对象 </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">对</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">感兴趣,但没有任何软件编程基础,想先从零基础入手的软件开发爱好者;希望从另外一些简单的其他语言转型从事</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">开发的求职人员。适合大学生学习计算机入门,通过</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">语言计算机二级。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">想从事编程开发的人员、具有计算机基础、面试不过关的待业者、出校门的大学生、以及编程能力提升的从业者、以及世界</span><span style="font-family:Calibri;">500</span><span style="font-family:'Microsoft YaHei';">强的</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">工程师。</span> </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;">   </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 课程目标: </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">你将对</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">内容有个全面的掌握,助编程能力的提升,让你理解</span><span style="font-family:Calibri;">500</span><span style="font-family:'Microsoft YaHei';">强企业要求的难度,通过计算机二级</span><span style="font-family:'Microsoft YaHei';">java</span><span style="font-family:'Microsoft YaHei';">语言考试</span> </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;">   </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 学习计划 </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">如果是待业者,明天用</span><span style="font-family:Calibri;">8</span><span style="font-family:'Microsoft YaHei';">个小时,会在两个月内完成。如果是上班族,每周至少用</span><span style="font-family:Calibri;">12-20</span><span style="font-family:'Microsoft YaHei';">小时,</span><span style="font-family:Calibri;">4-6</span><span style="font-family:'Microsoft YaHei';">个月内完成。课后有附加资料和练习来巩固知识并加强编程能力。此课程注重</span><span style="font-family:Calibri;">500</span><span style="font-family:'Microsoft YaHei';">强企业的编程能力实战要求。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">是一门面向对象编程语言,不仅吸收了</span><span style="font-family:Calibri;">C++</span><span style="font-family:'Microsoft YaHei';">语言的各种优点,还摒弃了</span><span style="font-family:Calibri;">C++</span><span style="font-family:'Microsoft YaHei';">里难以理解的多继承、指针等概念,因此</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">语言具有功能强大和简单易用两个特征。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点</span><span style="font-family:Calibri;"><span>  </span></span><span style="font-family:'Microsoft YaHei';">。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">可以编写桌面应用程序、</span><span style="font-family:Calibri;">Web</span><span style="font-family:'Microsoft YaHei';">应用程序、分布式系统和嵌入式系统应用程序等。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java </span><span style="font-family:'Microsoft YaHei';">具备下列特性。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">1.</span><span style="font-family:'Microsoft YaHei';">简单性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">看起来设计得很像</span><span style="font-family:Calibri;">C++</span><span style="font-family:'Microsoft YaHei';">,但是为了使语言小和容易熟悉,设计者们把</span><span style="font-family:Calibri;">C++</span><span style="font-family:'Microsoft YaHei';">语言中许多可用的特征去掉了,这些特征是一般程序员很少使用的。例如,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">不支持</span><span style="font-family:Calibri;">go to</span><span style="font-family:'Microsoft YaHei';">语句,代之以提供</span><span style="font-family:Calibri;">break</span><span style="font-family:'Microsoft YaHei';">和</span><span style="font-family:Calibri;">continue</span><span style="font-family:'Microsoft YaHei';">语句以及异常处理。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">还剔除了</span><span style="font-family:Calibri;">C++</span><span style="font-family:'Microsoft YaHei';">的操作过载(</span><span style="font-family:Calibri;">overload</span><span style="font-family:'Microsoft YaHei';">)和多继承特征,并且不使用主文件,免去了预处理程序。因为</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">没有结构,数组和串都是对象,所以不需要指针。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">能够自动处理对象的引用和间接引用,实现自动的无用单元收集,使用户不必为存储管理问题烦恼,能更多的时间和精力花在研发上。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">2.</span><span style="font-family:'Microsoft YaHei';">面向对象</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">是一个面向对象的语言。对程序员来说,这意味着要注意应中的数据和操纵数据的方法(</span><span style="font-family:Calibri;">method</span><span style="font-family:'Microsoft YaHei';">),而不是严格地用过程来思考。在一个面向对象的系统中,类(</span><span style="font-family:Calibri;">class</span><span style="font-family:'Microsoft YaHei';">)是数据和操作数据的方法的集合。数据和方法一起描述对象(</span><span style="font-family:Calibri;">object</span><span style="font-family:'Microsoft YaHei';">)的状态和行为。每一对象是其状态和行为的封装。类是按一定体系和层次安排的,</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">使得子类可以从超类继承行为。在这个类层次体系中有一个根类,它是具有一般行为的类。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">程序是用类来组织的。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">还包括一个类的扩展集合,分别组成各种程序包(</span><span style="font-family:Calibri;">Package</span><span style="font-family:'Microsoft YaHei';">),用户可以在自己的程序中使用。例如,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">提供产生图形用户接口部件的类(</span><span style="font-family:Calibri;">java.awt</span><span style="font-family:'Microsoft YaHei';">包),这里</span><span style="font-family:Calibri;">awt</span><span style="font-family:'Microsoft YaHei';">是抽象窗口工具集(</span><span style="font-family:Calibri;">abstract windowing toolkit</span><span style="font-family:'Microsoft YaHei';">)的缩写,处理输入输出的类(</span><span style="font-family:Calibri;">java.io</span><span style="font-family:'Microsoft YaHei';">包)和支持网络功能的类(</span><span style="font-family:Calibri;">java.net</span><span style="font-family:'Microsoft YaHei';">包)。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">3.</span><span style="font-family:'Microsoft YaHei';">分布性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">设计成支持在网络上应用,它是分布式语言。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">既支持各种层次的网络连接,又以</span><span style="font-family:Calibri;">Socket</span><span style="font-family:'Microsoft YaHei';">类支持可靠的流(</span><span style="font-family:Calibri;">stream</span><span style="font-family:'Microsoft YaHei';">)网络连接,所以用户可以产生分布式的客户机和服务器。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">网络变成软件应用的分布运载工具。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">程序只要编写一次,就可到处运行。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">4.</span><span style="font-family:'Microsoft YaHei';">编译和解释性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">编译程序生成字节码(</span><span style="font-family:Calibri;">byte-code</span><span style="font-family:'Microsoft YaHei';">),而不是通常的机器码。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">字节码提供对体系结构中性的目标文件格式,代码设计成可有效地传送程序到多个平台。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">程序可以在任何实现了</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">解释程序和运行系统(</span><span style="font-family:Calibri;">run-time system</span><span style="font-family:'Microsoft YaHei';">)的系统上运行。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">在一个解释性的环境中,程序开发的标准</span><span style="font-family:Calibri;">“</span><span style="font-family:'Microsoft YaHei';">链接</span><span style="font-family:Calibri;">”</span><span style="font-family:'Microsoft YaHei';">阶段大大消失了。如果说</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">还有一个链接阶段,它只是把新类装进环境的过程,它是增量式的、轻量级的过程。因此,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">支持快速原型和容易试验,它将导致快速程序开发。这是一个与传统的、耗时的</span><span style="font-family:Calibri;">“</span><span style="font-family:'Microsoft YaHei';">编译、链接和测试</span><span style="font-family:Calibri;">”</span><span style="font-family:'Microsoft YaHei';">形成鲜明对比的精巧的开发过程。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">5.</span><span style="font-family:'Microsoft YaHei';">稳健性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">原来是用作编写消费类家用电子产品软件的语言,所以它是被设计成写高可靠和稳健软件的。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">消除了某些编程错误,使得用它写可靠软件相当容易。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">是一个强类型语言,它允许扩展编译时检查潜在类型不匹配问题的功能。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">要求显式的方法声明,它不支持</span><span style="font-family:Calibri;">C</span><span style="font-family:'Microsoft YaHei';">风格的隐式声明。这些严格的要求保证编译程序能捕捉调用错误,这就导致更可靠的程序。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">可靠性方面最重要的增强之一是</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">的存储模型。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">不支持指针,它消除重写存储和讹误数据的可能性。类似地,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">自动的</span><span style="font-family:Calibri;">“</span><span style="font-family:'Microsoft YaHei';">无用单元收集</span><span style="font-family:Calibri;">”</span><span style="font-family:'Microsoft YaHei';">预防存储漏泄和其它有关动态存储分配和解除分配的有害错误。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">解释程序也执行许多运行时的检查,诸如验证所有数组和串访问是否在界限之内。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">异常处理是</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">中使得程序更稳健的另一个特征。异常是某种类似于错误的异常条件出现的信号。使用</span><span style="font-family:Calibri;">try/catch/finally</span><span style="font-family:'Microsoft YaHei';">语句,程序员可以找到出错的处理代码,这就简化了出错处理和恢复的任务。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">6.</span><span style="font-family:'Microsoft YaHei';">安全性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">的存储分配模型是它防御恶意代码的主要方法之一。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">没有指针,所以程序员不能得到隐蔽起来的内幕和伪造指针去指向存储器。更重要的是,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">编译程序不处理存储安排决策,所以程序员不能通过查看声明去猜测类的实际存储安排。编译的</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">代码中的存储引用在运行时由</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">解释程序决定实际存储地址。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">运行系统使用字节码验证过程来保证装载到网络上的代码不违背任何</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">语言限制。这个安全机制部分包括类如何从网上装载。例如,装载的类是放在分开的名字空间而不是局部类,预防恶意的小应用程序用它自己的版本来代替标准</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">类。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">7.</span><span style="font-family:'Microsoft YaHei';">可移植性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">使得语言声明不依赖于实现的方面。例如,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">显式说明每个基本数据类型的大小和它的运算行为(这些数据类型由</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">语法描述)。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">环境本身对新的硬件平台和操作系统是可移植的。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">编译程序也用</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">编写,而</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">运行系统用</span><span style="font-family:Calibri;">ANSIC</span><span style="font-family:'Microsoft YaHei';">语言编写。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">8.</span><span style="font-family:'Microsoft YaHei';">高性能</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">是一种先编译后解释的语言,所以它不如全编译性语言快。但是有些情况下性能是很要紧的,为了支持这些情况,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">设计者制作了</span><span style="font-family:Calibri;">“</span><span style="font-family:'Microsoft YaHei';">及时</span><span style="font-family:Calibri;">”</span><span style="font-family:'Microsoft YaHei';">编译程序,它能在运行时把</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">字节码翻译成特定</span><span style="font-family:Calibri;">CPU</span><span style="font-family:'Microsoft YaHei';">(中央处理器)的机器代码,也就是实现全编译了。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">字节码格式设计时考虑到这些</span><span style="font-family:Calibri;">“</span><span style="font-family:'Microsoft YaHei';">及时</span><span style="font-family:Calibri;">”</span><span style="font-family:'Microsoft YaHei';">编译程序的需要,所以生成机器代码的过程相当简单,它能产生相当好的代码。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">9.</span><span style="font-family:'Microsoft YaHei';">多线程性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">是多线程语言,它提供支持多线程的执行(也称为轻便过程),能处理不同任务,使具有线索的程序设计很容易。</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">的</span><span style="font-family:Calibri;">lang</span><span style="font-family:'Microsoft YaHei';">包提供一个</span><span style="font-family:Calibri;">Thread</span><span style="font-family:'Microsoft YaHei';">类,它支持开始线索、运行线索、停止线索和检查线索状态的方法。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">的线索支持也包括一组同步原语。这些原语是基于监督程序和条件变量风范,由</span><span style="font-family:Calibri;">C.A.R.Haore</span><span style="font-family:'Microsoft YaHei';">开发的广泛使用的同步化方案。用关键词</span><span style="font-family:Calibri;">synchronized</span><span style="font-family:'Microsoft YaHei';">,程序员可以说明某些方法在一个类中不能并发地运行。这些方法在监督程序控制之下,确保变量维持在一个一致的状态。</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">10.</span><span style="font-family:'Microsoft YaHei';">动态性</span> </p> <p style="font-size:11.0pt;"> <span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">语言设计成适应于变化的环境,它是一个动态的语言。例如,</span><span style="font-family:Calibri;">Java</span><span style="font-family:'Microsoft YaHei';">中的类是根据需要载入的,甚至有些是通过网络获取的。</span> </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;">   </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> <span>尹成老师带你步入</span><span>Java</span><span>语言基础的殿堂,讲课生动风趣、深入浅出,全套视频内容充实,整个教程以</span><span>Java</span><span>语言为核心,完整精彩的演练了</span><span>Java</span><span>语言操作流程以及各种精彩的小项目等,提高竞赛能力,非常适合同学们学习!</span> </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 课程特色 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 特色一:通俗易懂 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 本视频语言简洁,通俗易懂,将难以理解的编程问题用简单清晰的语言描述,让你更容易理解。 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 特色三:内容丰富 </p> <p style="font-size:11.0pt;"> <span style="font-family:'Microsoft YaHei';">本视频讲解的</span><span style="font-family:'Microsoft YaHei';">java</span><span style="font-family:'Microsoft YaHei';">语言知识更加丰富翔实,较之其他视频,本视频讲解的</span><span style="font-family:Calibri;">java</span><span style="font-family:'Microsoft YaHei';">语言知识更多更深入。</span> </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 特色三:配图详尽 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 本视频在讲解知识点时都配图了表格或图示,在讲解案例时,都配备了流程图或分析图示,让你对所学知识点或案例理解更清晰。 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 特色四:实战性强 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 本视频讲解的每个知识都配备了一个小案例,这样既增加了学生动手能力,又巩固了学生所学知识。 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 特色五:加入尹成老师微信群 </p> <p style="font-family:'Microsoft YaHei';font-size:11.0pt;"> 本视频尹成老师亲自答疑 </p>
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页