如题。。。
101
binjoo 2018-11-19 09:05:30 +08:00 14
```java
System.out.print("1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9"); System.out.print("2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18"); System.out.print("3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27"); System.out.print("4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36"); System.out.print("5x5=25 5x6=30 5x7=35 5x8=40 5x9=45"); System.out.print("6x6=36 6x7=42 6x8=48 6x9=54"); System.out.print("7x7=49 7x8=56 7x9=63"); System.out.print("8x8=64 8x9=72"); System.out.print("9x9=81"); ``` |
102
947211232 2018-11-19 09:13:03 +08:00
php 沐浴在你们的阳光下已经晒黑了...
|
103
2805408253 2018-11-19 09:13:55 +08:00
@binjoo 读书少,别骗我
|
104
hasbug 2018-11-19 09:18:02 +08:00
抱歉,我作为个好几年的前端,就没遇到这个题,我跟你说,别说 99 乘法表,再简单的我也不会!
|
105
sevenzhou1218 2018-11-19 09:22:14 +08:00
楼主 78 天前发的问题和 23 天前发的问题,相隔两个月,不是也没解决么。。。
|
106
LokiSharp 2018-11-19 09:27:10 +08:00
我十几年前用 C 写过,HelloWorld 之后写得就是他了。。。
|
107
wizardoz 2018-11-19 09:27:28 +08:00
你这个错了,九九乘法表是正三角,不是倒三角。
System.out.print("1*1=1 "); System.out.print("1*2=2 2*2=4 "); System.out.print("1*3=3 2*3=6 3*3=9 "); System.out.print("1*4=4 2*4=8 3*4=12 4*4=16 "); System.out.print("1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 "); System.out.print("1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 "); System.out.print("1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 "); System.out.print("1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 "); System.out.print("1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 "); |
108
DefineJ 2018-11-19 09:28:20 +08:00 via Android
99 乘法表表示还是初学才写吧,让他写算法哈哈哈
|
109
wsd15321 2018-11-19 09:28:27 +08:00
php 又被黑
|
110
dnsaq 2018-11-19 09:29:57 +08:00 via iPhone
所以 php 是世界上最好的语言?
|
111
pkookp8 2018-11-19 09:30:41 +08:00 via Android
# py
table = '''1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 6x6=36 6x7=42 6x8=48 6x9=54 7x7=49 7x8=56 7x9=63 8x8=64 8x9=72 9x9=81''' print(table) |
112
fyibmsd 2018-11-19 09:41:55 +08:00 1
```php
foreach(range(1, 9) as $i) { foreach(range(1, $i) as $j) { printf('%d*%d=%d ', $j, $i, $j * $j); } echo PHP_EOL; } ``` |
113
898601566 2018-11-19 09:48:30 +08:00
没事谁去写九九乘法表?
|
115
lrannn 2018-11-19 09:52:58 +08:00
Kotlin
``` for (i in 1 until 10) { for (j in 1..i) { print(" $i * $j = ${i * j} ") } println("\n") } ``` |
116
kimqcn 2018-11-19 09:53:44 +08:00
没毛病,去做红心浏览器妥妥的
|
117
aihidao 2018-11-19 09:58:21 +08:00
那么多关于薪资技术的贴子,都让我觉得自己是 v 站末流。
直到看到你的贴子,和你的贴子下的评论。 |
118
laoyuan 2018-11-19 10:01:19 +08:00
PHP_EOL 讲究,我都是<br>
|
119
Egfly 2018-11-19 10:02:15 +08:00
emmmm,虽然这样我还是要说:PHP 是世界最好的语言。 :dog
|
120
guoyuchuan 2018-11-19 10:08:47 +08:00
所以有工作经验多的人并不一定牛逼,说不定还很菜,而且这种人还很多;
|
121
haohappy 2018-11-19 10:13:22 +08:00
这是 hr 吧 等下就一个一个地私信了
|
123
8355 2018-11-19 10:17:45 +08:00
看了看楼主发的帖子..
|
124
AscenZ 2018-11-19 10:19:07 +08:00
Swift,Playground 随手写了个,哪位兄弟有更优雅的写法
```swift for col in 1...9 { var tmn = "" for row in 1...9 { if row == col { tmn = "\n" } if row <= col { print("\(row)x\(col)=\(col * row) ", separator: "", terminator: tmn) } } } ``` ``` 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 ``` |
125
saintatgod 2018-11-19 10:25:23 +08:00
我面试时候写过这个.
不过面试我的人说...我的输出没有换行, 格式不对, 所以写的是不对的. |
126
JerryCha 2018-11-19 10:36:45 +08:00
对不起我也写了十分钟
``` #include <stdio.h> void foo(int i, int j); int main() { foo(1,1); return 0; } void foo(int i, int j) { if (i > 9) printf(""); else { printf("%dx%d=%d\t", j, i, i*j); j++; if (j <= i) foo(i, j); else { printf("\n"); foo(i+1, 1); } } } ``` |
127
lbp0200 2018-11-19 10:42:02 +08:00
谭浩强的弟子必备吗?
非我族类,其心必异,让他滚。 |
128
YouLoveme 2018-11-19 10:58:46 +08:00
```bash
#!/bin/awk awk 'BEGIN{for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf j"x"i"="i*j"\t"};print}}' ``` ``` 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 ``` |
129
Neojoke 2018-11-19 11:03:00 +08:00
大家觉得,为什么要考量用代码实现九九乘法口诀表?目的是测试对方什么能力?
|
131
tailf 2018-11-19 11:05:56 +08:00
我也不会,但是我给 PHP 贡献过代码
|
132
yx13 2018-11-19 11:08:48 +08:00 via Android
<?php
$a = [1]; $i = 0; while (count($a) != 10) { $result = $a[$i] * $a[count($a)-1]; echo "{$a[$i]} X {$a[count($a)-1]} = " . "{$result}\t"; $i++; if (count($a) == $i) { $a[$i] = $a[count($a)-1] + 1; $i = 0; echo "\n"; } } ?> |
133
zifangsky 2018-11-19 11:12:46 +08:00
嗯,然后呢,影响 PHP 成为最好的语言吗?
|
134
jinzhe 2018-11-19 11:12:51 +08:00
凑个热闹
```js let line=""; for(let i=1;i<=9;i++){ for(let j=1;j<=i;j++){ line+=`${j}x${i}=${i*j}\t`; } line+=`\n`; } console.log(line); ``` 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 |
135
fanhuai 2018-11-19 11:16:07 +08:00
StringBuilder tx = new StringBuilder();
for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { tx.Append(j + "*" + i + "=" + j * i); tx.Append("\t"); } tx.Append("\n"); } richTextBox1.Text = tx.ToString(); |
136
JaguarJack 2018-11-19 11:18:26 +08:00
php -r "for($i=1;$i<=9;$i++){for($j=1;$j<=$i;$j++){echo sprintf('%d*%d=%d ', $i, $j, $i*$j);} echo PHP_EOL;}";
|
137
supuwoerc 2018-11-19 11:25:19 +08:00
就算再简单,我们也不会!~
|
138
icaca 2018-11-19 11:31:40 +08:00
不应该是二进制的么?
|
139
wuxi889 2018-11-19 11:37:48 +08:00 1
@yx13
<?php for ($i = 9; $i > 0; $i--) { for ($j = $i; $j > 0; $j--) { echo $i, ' × ', $j, ' = ', $i * $j, '|'; } echo PHP_EOL; } ?> |
141
183387594 2018-11-19 11:44:52 +08:00 1
起初他们写各种 XX 树,我没有说话,因为我不会写。现在你们竟然要写乘法口诀表,我...
|
142
liuxu 2018-11-19 11:48:19 +08:00
培训班出来的都是 2 年
|
143
yoshiyuki 2018-11-19 13:28:11 +08:00
你们这个岗位薪资多少? 面试官做了几年技术?
|
144
zjsxwc 2018-11-19 13:29:43 +08:00
起初他们写各种 XX 树,我没有说话,因为我不会写。现在你们竟然要写乘法口诀表,我...
|
145
Amance 2018-11-19 13:34:18 +08:00 1
管你什么事?你是负责人还是啥?你还是嫉妒?还是开不起他?你一个月的工资因为他少拿了?你见不惯别人拿这么高的工资?你付出的比他多很多?一天天没事做事,不要断别人财路,公司不是你开的你就省点心。
|
146
lideshun123 2018-11-19 13:39:41 +08:00
蛋逼吧
|
147
cincout 2018-11-19 14:16:49 +08:00 1
@AscenZ 这个是不是更优雅,哈哈哈哈
for i in 1...9 { var str = "" for j in 1...i { str += "\(j)x\(i)=\(i*j) " } print(str) } |
148
mmp123 2018-11-19 14:28:58 +08:00
python 一行就足够了
print ('\n'.join([' '.join(['%s*%s=%-2s' % (j,i,i*j) for j in range(1,i+1)]) for i in range(1,10)])) |
149
markgor 2018-11-19 14:34:19 +08:00
<?php
$IsCLI = preg_match("/cli/i", php_sapi_name()) ? true : false; $S_SPACE = $IsCLI ? ' ' : ' '; $S_EOL = $IsCLI ? PHP_EOL : '</br>'; for($col=1;$col<=9;$col++){ for($row=1;$row<=$col;$row++){ echo strpad($col) . '*' . strpad($row) . '=' . strpad($col*$row) . $S_SPACE; } echo $S_EOL; } function strpad($str){ GLOBAL $S_SPACE; return str_pad($str,3,$S_SPACE,STR_PAD_BOTH); } ?> 1 * 1 = 1 2 * 1 = 2 2 * 2 = 4 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 4 * 1 = 4 4 * 2 = 8 4 * 3 =12 4 * 4 =16 5 * 1 = 5 5 * 2 =10 5 * 3 =15 5 * 4 =20 5 * 5 =25 6 * 1 = 6 6 * 2 =12 6 * 3 =18 6 * 4 =24 6 * 5 =30 6 * 6 =36 7 * 1 = 7 7 * 2 =14 7 * 3 =21 7 * 4 =28 7 * 5 =35 7 * 6 =42 7 * 7 =49 8 * 1 = 8 8 * 2 =16 8 * 3 =24 8 * 4 =32 8 * 5 =40 8 * 6 =48 8 * 7 =56 8 * 8 =64 9 * 1 = 9 9 * 2 =18 9 * 3 =27 9 * 4 =36 9 * 5 =45 9 * 6 =54 9 * 7 =63 9 * 8 =72 9 * 9 =81 |
150
vicvinc 2018-11-19 14:42:03 +08:00
```javascript
const dp = new Array(10) .fill(0) .map((x, i) => new Array(10) .fill(0) .map((y, j) => (i > 0 && j > 0 ? `${i}*${j}=${i * j}` : 0)) .filter(x => x !== 0) ) .map(x => x.join(" ")) .filter(x => x !== "") .join("\n"); console.log(dp); ``` |
151
ashin 2018-11-19 14:43:31 +08:00 1
我随手写出来居然长这个样, 这算九九表吗
``` 1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 3 * 4 = 12 3 * 5 = 15 3 * 6 = 18 3 * 7 = 21 3 * 8 = 24 3 * 9 = 27 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54 7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 7 * 8 = 56 7 * 9 = 63 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 8 * 9 = 72 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 ``` |
152
vicvinc 2018-11-19 14:43:40 +08:00
up 一下:
`javascript const dp = new Array(10) .fill(0) .map((x, i) => new Array(10) .fill(0) .map((y, j) => (i > 0 && j > 0 && i >= j ? `${i}*${j}=${i * j}` : 0)) .filter(x => x !== 0) ) .map(x => x.join(" ")) .filter(x => x !== "") .join("\n"); console.log(dp); ` |
153
ashin 2018-11-19 14:45:21 +08:00
package main
import ( "fmt" ) func main() { for i := 1; i <= 9; i++ { for j := 1; j <= i + 0; j++ { fmt.Printf("%d * %d = %d\t", i, j, i*j) } fmt.Println() } } |
154
ruixingchen 2018-11-19 14:48:42 +08:00 via iPhone
两层循环,用第一层循环的值作为第二层循环的临界条件,就可以了吧,代码就不上了
|
155
ashin 2018-11-19 14:50:10 +08:00
我改了三次才写对 哈哈 要被楼主鄙视
package main import ( "fmt" ) func main() { for i := 1; i <= 9; i++ { for j := 1; j <= i; j++ { fmt.Printf("%d * %d = %d\t", j, i, i*j) } fmt.Println() } } 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 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 |
156
90safe 2018-11-19 14:51:44 +08:00
```
for ($i=1; $i < 10; $i++) { for ($x=1; $x < 10; $x++) { $arr[$i * $x] = "$i * $x = " . $i * $x . PHP_EOL; } } ``` |
157
hauzi 2018-11-19 15:03:10 +08:00
<?php
for ($i = 1; $i <= 9; $i++) { for ($j = $i; $j <= 9; $j++) { print($i);print('*');print($j);print('=');print($i*$j);print(' '); } echo PHP_EOL; } ?> |
160
fyibmsd 2018-11-19 18:29:40 +08:00
|
161
NG6 2018-11-19 20:55:28 +08:00
炸一弄我也有点懵,赶紧打开 ide 写了一下
java 的,这东西有什么意义么 for(int x=1;x<=9;x++){ System.out.print("\n"); for (int y=1;y<=9;y++){ int z=x*y; System.out.print(x+"*"+y+"="+z+"\t"); } |
162
NG6 2018-11-19 21:24:44 +08:00
仔细一看还写错了,😅
for(int x=1;x<=9;x++){ System.out.print("\n"); for (int y=1;y<=x;y++){ int z=x*y; System.out.print(y+"*"+x+"="+z+"\t"); } } |
163
tmly200 2018-11-19 21:26:31 +08:00
又想起我那个 jq 切图从不出错效率极高的朋友了
|
165
yuikns 2018-11-20 03:04:25 +08:00 1
@AscenZ
println(( 1 to 9).map(i => (1 to i).map(j => s"$i x $j = ${i * j}").mkString(" ")).mkString("\n")) https://scastie.scala-lang.org/ovVNPVmgTa6ERTEtSIwV1A |
166
460881773 2018-11-20 09:43:52 +08:00
你的头像 是 ?
|
168
sununiq 2018-11-20 14:34:16 +08:00
```scala
(1 to 9) foreach { i => (1 to i) foreach { j => print(s"$j*$i=${i * j} ") } println() } ``` |
169
TheSpectre 2018-11-22 22:28:50 +08:00
会写又怎么样呢,业务代码与这些没有一点儿关系,公司只关心你能不能实现业务逻辑,才不管这些哦
|
170
thinkwei2012 2018-11-23 13:28:33 +08:00
```php
>>>MT 1x1=1 1x2=2 2x2=4 1x3=3 2x3=6 3x3=9 1x4=4 2x4=8 3x4=12 4x4=16 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 MT; 蛤蛤~ |
171
jss 2018-11-23 16:02:46 +08:00 via iPhone
我 3 年 还不会 我说啥了吗?
|
172
phpok 2018-11-24 10:23:37 +08:00
那个我好像也没有写过,不知道会还是不会,不过有规律可查的~,这个应该比较简单实现的吧,两次 for 嵌套执行~
|
173
phpdev 2018-12-02 11:44:23 +08:00
两次 for 嵌套?
|
174
chatfeed 2018-12-11 15:24:14 +08:00
@thinkwei2012 反了,<<<
|
175
superPHPer 2019-01-17 16:38:11 +08:00
小弟的算法菜的抠脚
|
176
aion 2019-02-25 19:11:20 +08:00
不会写乘法口诀表影响我写代码吗?
|