Import Java.util.Scanner;
/*
* Learning of operators in Java:
* Arithmetic operators: + 、-、 *,/and%, two integers, result or integer.
* Assignment operators: =, + =,-=, *=,/=,%=, &=, |=, ~=, ^=, <<=, >>=, >>>=, + +, and--。
* Comparison operators: = =,! =, <, <=, >, and >=.
* Logical operator:&&, | | And!.
* Bitwise operators:&, |, ~, ^, <<, >>, and >>>.
*
*/
public class Test {
public static void Main (string[] args) {
/*
* Function Application One: An integer in binary output (adjustable bits number)
*/
int Shuzi;
Scanner s=new Scanner (system.in);//Get console input
System.out.println ("Please enter an integer");
Find and return the next number from this console
Shuzi=integer.parseint (S.next ()); string conversion to Integer type
for (int i=7;i>=0;i--) {//i=7, representing 8-bit 2 binary i=31 32-bit binary
if ((shuzi& (1<<i))!=0) {
System.out.println ("1");
}else{
System.out.println ("0");
}
}
S.close ();
/*
* Function Application Two: Determine the number of digits of a number
*/
int q=1234578;
String str=q+ ""; Convert an integral type to a string first
System.out.println ("number" +str+ "is:" +str.length () + "number of digits");
/*
* Function Application Three: Reverse the output of a number
*/
int olddata=12345678;
int count= (olddata+ ""). Length ();
int newdata=0;
while (olddata!=0) {
for (int i=0;i<count;i++) {
newdata=newdata*10+olddata%10;
OLDDATA=OLDDATA/10;
}
System.out.println ("Newdata=" +newdata);
}
/*
* Function Application Four: Determine whether a number is a prime
*/
int num=3;
Boolean flag=true; The default is prime number
for (int i=2;i<=num/2;i++) {
if (num%i==0) {
Flag=false; If an even number jumps out of the loop
Break
}
}
if (flag) {
System.out.println (num+ "is a prime number!");
}else{
System.out.println (num+ "is not a prime number!");
}
}}
Java Learning Phase III: operator and structure learning