一个for实现9*9乘法表
public static void main(String[] args) {
new Test99().print(9);
}
运行结果:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
测试2:
public static void main(String[] args) {
new Test99().print(5);
}
运行结果:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
#include <stdio.h>
int _99;
void output(int n) {
for(int i=; i<=n; i++) {
for(int j=; j<=i; j++) {
printf("%4d",i*j);
}
puts("");
}
return ;
}
void output_one_for(int n) {
int i, j;
for(i=, j=; j<=n; i++) {
printf("%4d",i*j);
if(j==i) {
puts("");
i=;
j++;
}
}
return ;
}
bool output_one_for_zero_if(int n) {
int i;
for(i=; i<=n; i++) {
printf("%4d",i*n);
}
puts("");
return n==_99 || output_one_for_zero_if(n+);
}
void output_without_rec(int n){
int i, j;
for(i= ,j=;j<=n;i++){
printf("%4d",i*j);
i%j||puts("");
i%=j;
i||j++;
}
}
void pt(int n) {
_99 = n ;
puts("normal 9*9 list:");
output(_99);
puts("\nonly for 9*9 list:");
output_one_for(_99);
puts("\nonly one for with out if,switch,?: 9*9 list:");
output_one_for_zero_if();
puts("\nonly one for and without recursive to make 9*9 list:");
output_without_rec(_99);
return ;
}
int main() {
pt();
return ;
}
这个题目最难的地方莫过于换行, 昨天和【淦】日天交流这个题目的时候他也给出来另外一种换行的方法。
void ZRT(int n){
int i, j;
for(i=,j=;j<=n;i++){
printf("%4d",i*j);
printf("%c","\0\n"[i==j]); //意思就是将"\0\n"看作一个字符串的函数名,利用[i==j]来取输出'\0'还是'\n'。有趣的操作。
i%=j;
i||j++;
}
return ;
}
一个for实现9*9乘法表的更多相关文章
- 写一个方法,用一个for循环打印九九乘法表
public class MultiplicationTable { /** * @description 写一个方法,用一个for循环打印九九乘法表 * @author wangkun * ...
- JAVA - 一个for循环实现99乘法表
public class Test03 {public static void main(String[] args) { int lie = 1; for (int hang = 1; hang&l ...
- 9x9乘法表输出[Java]
笔试,9x9乘法表输出的问题,看似简单,回来把当时写的结果输入一遍后发现,并没有想象中的“完美”.把改写的pos在此,警示...不要忘记任何细节. public class NXN { public ...
- 使用JSP表达式和JSP脚本打印九九乘法表
首先使用JSP声明声明一个函数用于得到九九乘法表的内容 <%! String printMultiTable() { String s = ""; for (int i = ...
- PHP一个for循环输出9*9乘法表
一个for循环输出9*9乘法表 代码如下 <?php for ($i = 1, $j = 1; $i <= 9; $i++) { if ($i > $j) { $j++; $i = ...
- 使用Vue写一个九九乘法表
Vue.js是一套构建用户界面的渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计. 下面是在Vue 测试实例 - 菜鸟教程(runoob.com)使用Vue写的一个九九乘法表, ...
- 利用js的for循环实现一个简单的“九九乘法表”
For循环九九乘法表 for循环是javascript中一种常用的循环语句,可以很好的解决在程序中需要重复执行某些语句,利用for循环实现简单的“九九乘法表”的效果: 让循环从小到大,依次排序,并计算 ...
- 编写一个jsp页面,输出九九乘法表。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- 在网页中打印一个99乘法表--JavaScript描述
99乘法表使用for循环,在很多公司的面试中常会要求面试者手写这个算法,算是比较经典的for循环的应用 <!DOCTYPE html><html lang="en" ...
随机推荐
- KMP字符串模式匹配算法(C++实现)
鉴于原理有点复杂,详细原理可以参考这篇文章http://blog.csdn.net/v_july_v/article/details/7041827 本文直接从结论入手,应付考试和竞赛足够了. 设T为 ...
- 【汇编语言】Win10 安装 DOXBox0.74
1.下载package包,有用的只有前两个. 2.解压 masm 压缩文件,我把它解压到D盘. 3.双击 图1 中的 DOXBox 0.74.exe 进行安装. 4.打开 DOXBox0.74 (参考 ...
- mysql 重置密码
mysql 重置密码,跳过登录修改密码: # centos 上mysql 已经改名了,启动服务的时候注意是mariadb 了!!!!! # systemctl stop mariadb # syste ...
- git工具——对比文件的不同
对比工作区和某个版本中文件的不同: (1)继续编辑文件code.txt,在其中添加一行内容: (2)现在要对比工作区中code.txt和head版本中code.txt的不同,使用如下命令: 前面没有出 ...
- linux下双网卡双网关配置
要求: eth0:192.168.100.203 连接内网,网关为192.168.100.1.需要和192.168.10.0.192.168.12.0.192.168.100.0.10.2.2.0.1 ...
- Win10如何彻底禁用小娜?彻底禁用小娜的方法
原文地址:https://www.cnblogs.com/zhuimengle/p/5949152.html 小娜是Win10系统中的一款强大功能,有了它,我们对电脑的操作将更加方便.Win10系统有 ...
- 【Linux】常见基础命令之文件操作
vi:编辑文件 lilip@ubuntu:~/test/page$ vi test.txt i 切换到输入模式,以输入字符. x 删除当前光标所在处的字符. : ...
- C# emgu 多模板匹配
public MatchInfo GetMatchPos(string Src, string Template) { MatchInfo myMatchInfo = new MatchInfo(); ...
- router-link 返回上页 和 新窗口打开链接
1.如果使用了Vue-router的话,就可以用 this.$router.go(-1) 实现返回: 2.如果没使用vue-router,就可以用 window.history.go(-1) 实现返回 ...
- python2 使用pip安装psycopg2出现错误:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-mvzdNj/psycopg2/
公司业务需求,开发语言python2,需要使用数据库:postgresql,需要安装模块psycopg2这个模块, 使用pip install psycopg2 报错: Command "p ...