Inputs and operators

Source: Internet
Author: User
Tags arithmetic operators

Input from keyboard:

1 import java.util.*; // Reference Scan         2 Scanner sc=new Scanner (system.in); // defining an input scanner 3 System.out.print ("Please enter a number:"); 4 int num=sc.nextint (); //  5 String str=sc.next (); // reading the input string

Arithmetic operators:

                float Num1=12.45f;int num2=15; System.out.println (NUM1+NUM2); String str= "AA"; System.out.println (STR+NUM2); System.out.println (4.56-0.16); long num3=5l; System.out.println (NUM3*NUM1); int num4=7,num8=2; System.out.println (NUM4/NUM8); System.out.println (num4%3);

Self-increment decrement operator:

+ +-Same as + +

B=++a equivalent to A=a+1,b=a

b=a++ equivalent to B=a,a=a+1

int a=1;
int B, C;
b=a++;
System.out.println ("b=" +b+ "\ta=" +a);
A=1;
C=++a;
System.out.println ("c=" +c+ "\ta=" +a);

Results:

——

Comparison operators:

 1  char  char1= ' A ', char2= ' B ' ; 2  System.out.println (char1>char2);  3  ; 4  System.out.println (num1<num2);  5  System.out.println (' c ' = = ' C '  6  System.out.println (479>=426 7  System.out.println (12.45<=45.5    8  System.out.println (' y '! = ' t '); 

Logical operators:

Logic with:

&&:

1: When both sides at the same time to really return the result is true.

2: False on one side, return result is false

&: When the left value is false, the expression on the right still runs the check result is true or false

Logical OR:

|| :

1: When both sides are false at the same time, the return result is false.

2: One side appears true the return result is true.

        intNum1=10,num2=5; Booleanreg=false; Booleanreg1=true&& (reg=num1>num2); System.out.println (REG1+ "\ t reg=" +reg); Reg=false; BooleanReg2=false&& (reg=num1>num2); System.out.println (REG2+ "\ t reg=" +reg); Reg=false; Booleanreg3=true& (reg=num1>num2); System.out.println (Reg3+ "\ t reg=" +reg); Reg=false; Booleanreg4=false& (reg=num1>num2); System.out.println (REG4+ "\ t reg=" +reg); System.out.println (!true);

Inputs and operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.