提问人:Stormy Gamer 提问时间:11/30/2022 更新时间:2/15/2023 访问量:249
创建一个乘法表程序,通过使用Java用户定义的Method & For循环,输出将按照传递的参数进行
Create a Multiplication Table program, by using the Java user defined Method & For loop, the output will be according to the parameter passed
问:
在此处输入图像描述,我被要求精确地制作此表,但我无法弄清楚定义的方法是如何工作的!?
我尝试了很多,但就是失败了 不要,我做错了什么!
public class TABLE {
public int Multiplication;
public int multiply(int num)
{
for(int i = 1; i <= 10; ++i) {
System.out.printf("%d * %d = %d \n", num, i, num * i);
}
return multiply;
}
}
答:
0赞
user20641811
11/30/2022
#1
public static void multiply(int num)
{
for(int i = 1; i <= 10; ++i) {
System.out.printf("%d * %d = %d \n", num, i, num * i);
}
}
嗨,兄弟,你可以
0赞
Anup Kumar Gouda
2/10/2023
#2
//using user defined method By ITinnovation
import java.util.Scanner;
public class Table1
{
public void tab(int num1)
{
for(int i=1;i<=10;i++)
{
//System.out.println("The Table is:"+num1*i);
int multi=num1*i;
System.out.println(num1 + " x " + i + " = " + multi);
}
}
public static void main(String[] args) {
{
System.out.printf("Enter that value which you want to find out the table:");
Scanner sc= new Scanner(System.in);
int num1= sc.nextInt();
Table1 obj= new Table1();
obj.tab(num1);
}
}
}
评论
public void multiply(int num)
return multiply;
new TABLE().multiply(10);