找出 100 的所有因数
Find all factors of 100
我想得到所有乘以 100 的整数。例如,10*10=100。
package ex1;
import java.util.Scanner;
public class Ex1 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
input = new Scanner(System.in);
int i;
System.out.println("Please input a number");
i = input.nextInt();
for (int z = 1; z <= 10; z++) {
float y;
int x = 1;
y = i;
System.out.println("" + y / z + " * " + x * z + " = " + i);
}
}
}
这将为您提供 product
为 equal
至 100
的所有 integers
。 如果您想要 another
number
、simply change the 100
而非 any integer you want!
而不是 100
for (int i = 1; i<=100; i++) {
for (int j = 1; j<=100; j++) {
if (i*j==100) {
System.out.println(i + " " + j);
}
}
}
这里是您可以编译的所有内容 class 和 运行:
class product{
public static void main(String[] args) {
for (int i = 1; i<=100; i++) {
for (int j = 1; j<=100; j++) {
if (i*j==100) {
System.out.println(i + " " + j);
}
}
}
}
}
输出:
1 100
2 50
4 25
5 20
10 10
20 5
25 4
50 2
100 1
这听起来像是一道作业题....
在纸上尝试弄清楚如何在不使用代码的情况下解决这个问题,即手动解决示例 10*10=100。然后根据该逻辑编写代码。我对编码部分的一个提示是你应该看看模数运算符
我想得到所有乘以 100 的整数。例如,10*10=100。
package ex1;
import java.util.Scanner;
public class Ex1 {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
input = new Scanner(System.in);
int i;
System.out.println("Please input a number");
i = input.nextInt();
for (int z = 1; z <= 10; z++) {
float y;
int x = 1;
y = i;
System.out.println("" + y / z + " * " + x * z + " = " + i);
}
}
}
这将为您提供 product
为 equal
至 100
的所有 integers
。 如果您想要 another
number
、simply change the 100
而非 any integer you want!
for (int i = 1; i<=100; i++) {
for (int j = 1; j<=100; j++) {
if (i*j==100) {
System.out.println(i + " " + j);
}
}
}
这里是您可以编译的所有内容 class 和 运行:
class product{
public static void main(String[] args) {
for (int i = 1; i<=100; i++) {
for (int j = 1; j<=100; j++) {
if (i*j==100) {
System.out.println(i + " " + j);
}
}
}
}
}
输出:
1 100
2 50
4 25
5 20
10 10
20 5
25 4
50 2
100 1
这听起来像是一道作业题....
在纸上尝试弄清楚如何在不使用代码的情况下解决这个问题,即手动解决示例 10*10=100。然后根据该逻辑编写代码。我对编码部分的一个提示是你应该看看模数运算符