Java code example (3)

Source: Internet
Author: User

1 /**2 * Demand Analysis: Depending on whether the number of days entered is Saturday or Sunday,3 * and the weather temperature is greater than 28 degrees Celsius, then go out to swim, otherwise fishing4  * @authorChenyanlong5 * Date: 2017/10/146  */7  Packagecom.hp.test03;8 9 ImportJava.util.Scanner;Ten  One  Public classhs_judgeoutgoing { A  -      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub the         intDay ; -         Doubletemperature; -         //double temperature = 0.0; -          +System.out.println ("Please enter today's Day of the week, if week N, please enter" n ", Eg:7");  -Scanner input=NewScanner (system.in); +day=input.nextint (); A          at         if(day==6| | Day==7){ -             //Temperature Judgment -System.out.println ("Please enter today's temperature, eg:29.8");  -Scanner input2=NewScanner (system.in); -Temperature=input2.nextdouble (); -SYSTEM.OUT.PRINTLN ("Temp:" +temperature); in             if(temperature>25){ -System.out.println ("Fitness Today – swimming"); to}Else{ +System.out.println ("For Today-fishing"); -             } the}Else{ *System.out.println ("You still write code!! "); $         }Panax Notoginseng          -          the     } +}
1 /**2 * Demand Analysis: Judge whether the grade is qualified3  */4  Packagecom.hp.test03;5 6 ImportJava.util.Scanner;7 8  Public classHs_judgescore {9 Ten      Public Static voidMain (string[] args) { One         //TODO auto-generated Method Stub A          intscore; -System.out.println ("Please enter your score"); -           theScanner input=NewScanner (system.in); -Score=input.nextint (); -           -          //Judging whether the grade is qualified +          if(score<60){ -System.out.println ("Failed grades"); +}Else if(score<70){ ASystem.out.println ("Poor grades"); at}Else if(score<80){ -System.out.println ("Average grade"); -          } -          Else if(score<90){ -System.out.println ("Good grades"); -}Else{ inSystem.out.println ("Good grades"); -          } to           +     } -  the}
/*** Requirements: According to the sum of the decomposed figures, determine whether the user won the lottery *@authorChenyanlong * Time: 2017/10/14*/ Packagecom.hp.test03;ImportJava.util.Scanner; Public classHs_sumgetmp3 { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//define all the variables used        intnum,a,b,c,d,sum; System.out.println ("Please enter the 4-digit membership card number:"); //input and reading of keyboard dataScanner input=NewScanner (system.in); Num=Input.nextint (); //separating num, extracting thousands, hundreds, 10 digits, digitsSYSTEM.OUT.PRINTLN ("Membership card number is:" +num); System.out.println ("----------------------------------"); A=num/1000;//thousandb=num/100%10;//Hundredc=num/10%10;//10 Guestsd=num%10;//DigitSystem.out.println ("Thousand:" +a+ ", Hundred Number:" +b+ ", 10 digits:" +c+ ", single digit:" +d); System.out.println ("----------------------------------"); //the sum of a,b,c,dsum=a+b+c+D; System.out.println ("Membership card number" +num+ "each bit of the sum:" +sum); //judging whether or not to win        if(sum>30) {System.out.println ("Membership card number" +num+ ", you won the lottery! The prize is the latest version of the Sword Hao skin!!! "); }Else{System.out.println ("I'm sorry, you didn't win!"); }    }}
1 /**2 * Requirements: Basic use of Switch3  * @authorChenyanlong4 * Time: 2017/10/145  */6  Packagecom.hp.test03;7 8 ImportJava.util.Scanner;9 Ten  Public classHs_switch { One  A      Public Static voidMain (string[] args) { -          -       intScore,a; theSystem.out.println ("Please enter your score:"); -Scanner input=NewScanner (system.in); -Score=input.nextint (); -         +A=score/10; -        Switch(a) { +            Case10: A            Case9: atSystem.out.println ("excellent"); -                Break; -            Case8: -System.out.println ("Good"); -                Break; -            Case7: inSystem.out.println ("Medium"); -                Break; to            Case6: +System.out.println ("Poor"); -                Break; the          default: *System.out.println ("Failed"); $        }Panax Notoginseng       -     } the  +}
1 /**2 * Requirement Analysis: Basic use of three mesh operators3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test03;7 8  Public classHs_ternaryoperator {9 Ten      Public Static voidMain (string[] args) { One         //TODO auto-generated Method Stub A        intmin=3<1?2:3;//condition is False, enter 3 -System.out.println ("Output:" +min); -         the        intmin2=3>1?2:3;//condition is ture, enter 2 -System.out.println ("Output:" +min2); -         -     } +  -}

Java code example (3)

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.