Java Exercises with answers

Source: Internet
Author: User

First question int x = 1,y=1;if (x++==2 & ++y==2) {x = 7;} System.out.println ("x=" +x+ ", y=" +y);//x=2,y=2---------------------------------------------------second question int x = 1,y = 1; if (x++==2 && ++y==2) {x = 7;} System.out.println ("x=" +x+ ", y=" +y); X=2,y=1---------------------------------------------------third question int x = 1,y = 1;if ( X++==1 | ++y==1) {x = 7;} System.out.println ("x=" +x+ ", y=" +y); x=7,y=2---------------------------------------------------question Fourth int x = 1,y = 1;if ( X++==1 | | ++y==1) {x = 7;} System.out.println ("x=" +x+ ", y=" +y);//x=7,y=1---------------------------------------------------question Fifth Boolean b = True;if (B=false)  //if written as if (b=false) have results? If so, what is the result? System.out.println ("a"), else if (b) System.out.println ("B"), else if (!b) System.out.println ("C"); ElseSystem.out.println ("D");//bif (b=false)//c---------------------------------------------------the sixth question int x = 2,y=3; Switch (x) {default:y++;case 3:y++;case 4:y++;} System.out.println ("y=" +y);//y=6

  

11.2 the students are known to score 100 out of a total of 5 grades: A,b,c,d,e. 390~100 to rank a,80~89 for grade b,70~79 is Class C,460~69 to rank d,0~59 is level E. 5 requires defining a performance variable that, when the score changes, can be directly aware of the grade corresponding to that grade. 6 For example: When the score is 100, the student's grade is a. 7 8 classDemo9 {Ten     //defines a function that obtains the rank corresponding to the score by a given score.  One     /* A 1, clear the result of this function: Rank char - 2, there is no unknown content. Scores. int -     */ the      Public StaticString Getlevel (intnum) -     { -         CharLevel ; -         if(Num>=90 && num<=100) +Level = ' A '; -         Else if(Num>=80 && num<=89) +Level = ' B '; A         Else if(Num>=70 && num<=79) atLevel = ' C '; -         Else if(Num>=60 && num<=69) -Level = ' D '; -         Else -Level = ' E '; -  in         returnLevel ; -     } to      Public Static voidMain (string[] args) +     { -          the         Charch = getlevel (35); *System.out.println ("level=" +ch); $     }Panax Notoginseng      - } the  +  A  the  +  -  $2. $ write out the results.  - classDemo - { the      Public Static voidMain (string[] args) -     {WuyiShow (0);// the theShow (1);// - -     }     Wu      Public Static voidShowinti) -     { About         Switch(i) $         {     -             default: -i+=2; -              Case1: AI+=1; +              Case4: theI+=8;  -              Case2: $I+=4; the         } theSystem.out.println ("i=" +i); the     }     the } -  in3. Writes out the result of the output. the classDemo the { About      Public Static voidMain (string[] args) the     { the         intX=0,y=1; the         if(++x==y--&x++==1| | --y==0) +System.out.println ("x=" +x+ ", y=" +y);//x=2,y=0 -         Else theSystem.out.println ("y=" +y+ ", x=" +x);Bayi     } the } the  -  -4. the find out between 1~100, even if 3 is another multiple of 7 occurrences?  the  the  the  -5. the The following results are displayed in a procedural way.  the  the1*1=1941*2=2 2*2=4 the1*3=3 2*3=6 3*3=9 the1*4=4 2*4=8 3*4=12 4*4=16 the1*5=5 2*5=10 3*5=15 4*5=20 5*5=2598  About  -6. Write out the program results. 101 102 classDemo103 {104      Public Static voidMain (string[] args) the     {106         intx = 1;107          for(Show (' A '); Show (' B ') && x<3; Show (' C ')))108         {109Show (' d ');  theX + +;111         } the     }113      Public Static BooleanShowCharch) the     { the System.out.println (CH); the         return true;117     }118 }119  - //a b d c b d C b

Java Exercises with answers

Related Article

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.