发新话题
打印

[Java] 怎样编一个乘法表?

怎样编一个乘法表?

我想用JAVA编一张乘法表,格式如下,请教:怎样编:
           1     2     3……9
1         1
2          2     4
3          3     6     9
……
9         9    18    27……81
blog:http://blog.cfan.com.cn/?133855

TOP

真考验设计规划……
你把它列几行,应该会发现规律- -

TOP

我当然知(规律)啦,但不会输出这种格式呢。
blog:http://blog.cfan.com.cn/?133855

TOP

给你一个C++版的好了~然后根据C++的改成JAVA的……
事实证明,上校偶果然算法很硕……如此简单的一个东西,代码写的毫无美感可言- -!:s006:

下面是代码:
引用:
#include <conio.h>
#include <iostream>
#include "SolveHead.h"
using namespace std;

int main()
{
  
int z = 0;

  
cout<<"   ";  
// 为了第一行的那个空

  
for (int y = 0; y < 10; y++)  // 纵轴
  
{
   
for (int x = 1; x < 10; x++)  
// 横轴
   
{
      
if (0 == y)  
// 横轴上的数字
      
{
        
cout<<x<<"  ";
        
continue;
      }
      
z = x * y;  
// 计算结果
      
      
if (y == z)  // 纵轴上的数字
      
{
        
cout<<y<<"  ";
      }
      
cout<<z<<"  ";
    }
   
cout<<endl;
  }

  
cout<<endl<<"Press any key to exit!"<<endl;
  
getch();
  
return 0;
}
附件: 您所在的用户组无法下载或查看附件

TOP

回复 4楼 的帖子

我不会C++呀,所以你的代码有些看不懂。
blog:http://blog.cfan.com.cn/?133855

TOP

头文件不要管他~
cout<<是输出流
<<endl是换行符
getch();表示隐式的接受一个按键返回~

TOP

别用getch

TOP

py也有getch...不过是在这个module里面~

msvcrt – Useful routines from the MS VC++ runtime
Platforms: Windows

TOP

- -
习惯了……
反正都是VS……

TOP

空格你用\t...

TOP

回复 10楼 的帖子

想过,但是感觉MS会走样
起码我Debug的时候走样了……

TOP

全都% 2d不久行了= =
Welcome to JAFTBlog:http://blog.icybear.cn

TOP

回复 12楼 的帖子

%3d

2d就没空格了

TOP

发新话题