集册 Java实例教程 使用if语句,关系运算符和相等运算符比较整数。

使用if语句,关系运算符和相等运算符比较整数。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

931
使用if语句,关系运算符和相等运算符比较整数。
/** from N o w J a v a . c o m - 时代Java**/

import java.util.Scanner;


public class Main 

{

   // main method begins execution of Java application

   public static void main(String[] args)

   {

      // create Scanner to obtain input from command line

      Scanner input = new Scanner(System.in);


      int number1; // first number to compare

      int number2; // second number to compare


      System.out.print("Enter first integer: "); // prompt 

      number1 = input.nextInt(); // read first number from user 


      System.out.print("Enter second integer: "); // prompt 

      number2 = input.nextInt(); // read second number from user 

      /**n  o  w  j  a  v  a . c o m**/

      if (number1 == number2) 

         System.out.printf("%d == %d%n", number1, number2);


      if (number1 != number2)

         System.out.printf("%d != %d%n", number1, number2);


      if (number1 < number2)

         System.out.printf("%d < %d%n", number1, number2);


      if (number1 > number2)

         System.out.printf("%d > %d%n", number1, num
展开阅读全文