Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Java judges odd and even numbers.
Java judges odd and even numbers.
The code is as follows:

Import java.util.scanner;

Public class woo {

Public static void main (strinargs []) {

Scanner scan = new scanner (system. in);

System.out.println ("input integer");

int a = scan . nextbyte();

If (a%2! = 0)

System.out.printf("%d is odd ",a);

other

System.out.printf("%d is even ",a);

}

}

Extended data:

In the Java core API, there are many examples of applying final, such as java.lang.String, and the whole class is final. Specifying a final modifier for a class will make it impossible for the class to be inherited, and specifying a final modifier for a method will make it impossible for the method to be overridden.

If a class is designated as final, all methods of the class are final. The Java compiler will look for opportunities to inline all final methods, which plays an important role in improving the running efficiency of Java. For more information, see Java runtime optimization. This can improve performance by an average of 50%.

Especially for the use of string objects, StringBuilder/StringBuffer should be used instead of string connection. Because Java virtual machine not only takes time to generate objects, but also may take time to collect and process these objects in the future, generating too many objects will have a great impact on the performance of the program.

References:

Baidu encyclopedia-odd number

Baidu encyclopedia-even number