zoukankan      html  css  js  c++  java
  • Java练习 SDUT-2561_九九乘法表

    九九乘法表

    Time Limit: 1000 ms Memory Limit: 65536 KiB
    Problem Description

    九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题。《九九乘法歌诀》,又常称为“小九九”,如下图所示。你的任务是写一个程序,对于给定的一个正整数 n ,输出“九九乘法表”的前 n 行。例如,输入 n 为 9,你的程序的输出将为下图:

    Input

    输入包含多组测试数据,以 EOF 结束。每组测试数据只包含一个正整数 n (0 < n < 10)。

    Output

    对于每组测试数据,输出上图所示“九九乘法表”的前 n 行。

    Sample Input

    2
    3

    Sample Output

    11=1
    1
    2=2 22=4
    1
    1=1
    12=2 22=4
    13=3 23=6 3*3=9

    Hint

    必须使用for循环,如果你的代码中出现例如

    if(n == 1) printf(“1*1=1 ”);

    if(n == 2) printf(“11=1 12=2 2*2=4 ”);

    或其类似语句,本题不得分。

    注意使用for循环,然后结尾没有空格。

    import java.util.*;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner cin = new Scanner(System.in);
    		int n,i,j;
    		while(cin.hasNext())
    		{
    			n = cin.nextInt();
    			for(i=1;i<=n;i++)
    			{
    				for(j=1;j<=i;j++)
    				{
    					if(j!=i)
    						System.out.printf("%d*%d=%d ",j,i,i*j);
    					else
    						System.out.printf("%d*%d=%d
    ",j,i,i*j);
    				}
    			}
    		}
    		cin.close();
    	}
    }
    
  • 相关阅读:
    深度学习面试问题
    重新学习pytorch的库函数等..
    新电脑的操作系统win10的所有设置问题汇总
    二叉搜索树,和红黑树,
    Most common words
    Word histogram
    Random numbers
    Word frequency analysis
    DSU
    Sequences of sequences
  • 原文地址:https://www.cnblogs.com/luoxiaoyi/p/9706285.html
Copyright © 2011-2022 走看看