打印整数的Java程序

68 阅读1分钟

写一个Java程序来打印一个整数作为输出。在这个例子中,我们声明了一个整数类型的数字变量,并将55分配给它。接下来,我们使用System.out.printf语句来打印这个整数作为输出。

 package SimpleNumberProgramspublic class PrintInteger {

public static void main(String\[\] args) {
	int number = 55;
	System.out.printf("\\nThe integer values = %d", number );
}

}

The integer values = 55

这个Java程序允许用户输入任何整数值,并打印该数值作为输出。

package SimpleNumberPrograms;

import java.util.Scanner;

public class PrintInteger2 { private static Scanner sc;

public static void main(String\[\] args) {
	int number;
	sc = new Scanner(System.in);
	
	System.out.print("Please Enter the integer Value = ");
	number = sc.nextInt();

	System.out.println("\\nThe integer value you have entered = " + number);
}

image.png