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