Ask for the lowest price for a batch of discounted books

Source: Internet
Author: User

Design ideas:

The lowest price of the first five books has been calculated, each additional book, the money spent will increase 8 7.2 6 4.4 or 4.4 yuan so the cycle down

Source:

ImportJava.util.Scanner; Public classMinmoney { Public Static voidMain (String args[]) {intBooknumber=0; DoubleMoney=0; Scanner in=NewScanner (system.in); System.out.print ("How many Harry Potter do you want to buy?" "); Try{Booknumber=In.nextint (); }        Catch(Exception e) {System.out.print ("Booknumber input Error"); }        if(booknumber<=0) {System.out.print ("Are you here to buy a book?" "); System.exit (0); }        //1-5 of the lowest price        if(booknumber<=5){            if(booknumber==1) money=8; if(booknumber==2) money=15.2; if(booknumber==3) money=21.6; if(booknumber==4) money=25.6; if(booknumber==5) money=30; }         //five above the lowest price adjacent to the lowest price difference is 8 7.2 6 4.4 4.4 Cycle        Else{            if(booknumber%5==0) money= (BOOKNUMBER/5) *30; if(booknumber%5==1) money=8+ (BOOKNUMBER/5) *30; if(booknumber%5==2) money=15.2+ (BOOKNUMBER/5) *30; if(booknumber%5==3) money=21.2+ (BOOKNUMBER/5) *30; if(booknumber%5==4) money=25.6+ (BOOKNUMBER/5) *30; } System.out.println ("Lowest Price is:" +Money ); }}

Realize:

Personal Summary:

First calculate the lowest price of the first few, find the law, and then realize the function on the line.

Ask for the lowest price for a batch of discounted books

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.