public class x{
public static void Main (string[] args) {
First question
System.out.println ("5+5=" +5+5);
Second question
int a=3,b;
b=a++;
System.out.println ("a=" +a+ ", b=" +b);
Third question
Short s=3;
S= (short) (s+4);//Incompatible type: conversion from int to short can be a loss. +short
System.out.println ("s=" +s);
Fourth bitwise operator
System.out.println (6&3);//unconditional and
System.out.println (6|3);//unconditional or
System.out.println (3^3);//When not the same time for true 1 and 0 for the same time as false 0 and 0 1 and 1
System.out.println (3<<2);//left shift is actually used to calculate 3*2^2=12
System.out.println (3>>1);//Right Shift is actually used to calculate the division 3/(2^1) =1//sop (3>>>1) is also the right shift, the difference is that the occurrence of the empty space with 0 complement
Question Fifth ternary operator
int x=3,y;
y=x>1?100:200;//ternary condition, determine whether x is greater than 1, if y=100, if not y=200, right binding
System.out.println ("y=" +y);
Use ternary operators to make contact
int z=15,q=10,v=8,e;
System.out.println (E=Z>Q?Z:Q);//output A large integer of two integers
System.out.println (E=Z>Q?Z:Q>V?Q:V);//output the largest integer in three integers
Judgment Statement of the sixth question
int weekday=3;//Judging Week
if (weekday==1) {
System.out.println ("Today is Monday");
}
else if (weekday==2) {
System.out.println ("Today is Tuesday");
}
else if (weekday==3) {
System.out.println ("Today is Wednesday");
}
else if (weekday==4) {
System.out.println ("Today is Thursday");
}
else if (weekday==5) {
System.out.println ("Today is Friday");
}
else if (weekday==6) {
System.out.println ("Today is Saturday");
}
else if (weekday==7) {
System.out.println ("Today is Sunday");
}
else{
System.out.println ("Without this Day");
}
int month=8;//Judging season
if (month==3| | month==4| | month==5) {
System.out.println ("Now is Spring");
}
else if (month==6| | month==7| | MONTH==8) {
System.out.println ("Now is Summer");
}
else if (month==9| | month==10| | month==11) {
System.out.println ("Now is Autumn");
}
else if (month==12| | month==1| | month==2) {
System.out.println ("Now is Winter");
}
else{
System.out.println ("Without this season");
}
Question seventh using branch statements
int c=84,h=3;
Char option= ' + ';
Switch (option)
{
Case ' + ':
System.out.println ("c+h=" + (c+h));
Break
Case '-':
System.out.println ("c-h=" + (c-h));
Break
Case ' * ':
System.out.println ("c*h=" + (c*b));
Break
Case '/':
System.out.println ("c/h=" + (c/h));
Break
Case '% ':
System.out.println ("c%h=" + (c%h));
Break
Default
System.out.println ("c%h=" + (c%h));
Break
}
Use switch to judge the season
int mon=8;
Switch (Mon)
{
Case 3:
Case 4:
Case 5:
System.out.println ("Now is Spring");
Break
Case 6:
Case 7:
Case 8:
System.out.println ("Now is Summer");
Break
Case 9:
Case 10:
Case 11:
System.out.println ("Now is Autumn");
Break
Case 12:
Case 1:
Case 2:
System.out.println ("Now is Winter");
Break
Default
System.out.println ("Without this season");
Break
}
The difference between do and while in question eighth
int d=1;
bo=
System.out.println ("d=" +d);
d++;
}while (d<1);//Regardless of whether the conditions in the while are set, do everything inside to run
int f=1;
while (f<1) {
System.out.println ("f=" +f);
f++;
}
Question Nineth Write a simple loop statement using the FOR statement
for (int g=1;g<5;g++)
{
System.out.println ("g=" +g);
}
}
}
Java Programming Day Job