Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - 1. Write a complete Java application, declare two integer variables, assign values ??respectively, and output their size relationship on the screen.

import java.util.Scanner;

class Comp

1. Write a complete Java application, declare two integer variables, assign values ??respectively, and output their size relationship on the screen.

import java.util.Scanner;

class Comp

1. Write a complete Java application, declare two integer variables, assign values ??respectively, and output their size relationship on the screen.

import java.util.Scanner;

class Compare

{

private int a; /*integer variable member a* /

private int b; /*integer variable member b*/

public int scanInt(String type)

{

Scanner scan = null;

while (true)

{

try{/*Exception catching*/

scan = new Scanner (System.in);

System.out.print("Please enter the value of "+type+":");

return scan.nextInt();

}catch(Exception e){/*Exception handling*/

System.out.println("The data you entered is wrong!");

}

}

}

public void compareInt()/*Output size relationship after comparison*/

{

if (a==b)

System.out.println(a+"="+b);

else

System.out.println(a> b?a+">"+b:a+"<"+b);

}

public static void main(String[] args)

{

Compare c = new Compare();

c.a = c.scanInt("a");

c.b = c.scanInt("b") ;

c.compareInt();

}

}