運算子第二次課

來源:互聯網
上載者:User

標籤:運算式   優秀   面積   第二次課   float   out   邏輯運算子   string   儲存   

/*
//課前練習:兩道題
//編程計算:一個白領工作加班了89個小時,編程計算共加了多少天零多少小時?

int x=89;
int y=89/24;//儲存加了幾天班
int z=89%24;
System.out.println("加班了"+y+"天"+z+"小時");
//求長方形的周長c和面積s,設長方形的長、寬分別為a,b

float a,b,c,s;
a=3;
b=2;
c=(a+b)*2;
s=a*b;
System.out.println("面積是"+s+"周長是"+c);
int a=3;
int b=2;
//任務一:算術運算子(下篇)
//a+=b;//a=a+b;
//a-=b;
//a*=b;
a/=b;

a%=b;

System.out.println(a);

int m=5;
m+=1;
System.out.println("m="+m);*/

//任務二:比較子
System.out.println(3==2);
System.out.println(3!=2);
//任務三:邏輯運算子
System.out.println((3==2)&(3!=2));
System.out.println((3==2)|(3!=2));
System.out.println(!(3>2));
System.out.println((7>=6)&(3==1));//false

System.out.println((3==1)&&(7>=6));
System.out.println(3==1&7>=6);
//任務四:練習寫運算式
// x<=0

//(x>0)&&(x<5)
// (x>=0)&&(x<=10)
// x<=5|x>=10

//任務五:寫思評分的運算式s
//不及格:0<=s && s<60
//及格: s>=60 && s<80
//良好: s>=80 && s<90
//優秀: s>=90 && s<=100

//任務六:三元運算子 有兩條分支
String str= 3<2?"aaa":"bbb";
System.out.println(str);

/*求運算式的值
y = |x| x為整數,y為x的絕對值
如果 x>=0 y = x
x<0 y = - x*/
int x=-3,y;
//x>=0?x:-x;
y=x<0?-x:x;
System.out.println(y);

運算子第二次課

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.