我想用更像System.out.print(+int a"是"+int b的倍数"的倍数)替换关于"第一个数字是第二个数字的倍数"的位;有什么建议吗?我正在使用的代码如下。
import java.util.Scanner;
public class Multiples {
public static void main( String[] args ) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter two integers " );
int a = scan.nextInt(); // First number input by user
int b = scan.nextInt(); // Second number input by user
if ( a % b == 0 )// is a a multiple of b
System.out.print("The first number is a multiple of the second.");
else
System.out.print("The first number is not a multiple of the second.");
}
}
你可以简单地做:
System.out.print( a + " is a multiple of " + b); // Or System.out.println()
或使用printf()
System.out.printf("%d is a multiple of %d", a, b);