Design ideas: The number of books divided by 10, take the whole B, take the remainder a, respectively, according to the 1--9 book when the best discount program calculation, and add the whole time 2a 5 to calculate.
Program code:
Package Book;import Java.util.scanner;import java.lang.*;p ublic class Test {public static void Main (String arg[]) { int i,j=0; Scanner input =new Scanner (system.in); System.out.println ("Please enter the number of books purchased:"); int num=input.nextint (); int a=num%10;//means remainder int b=num/10;//take integer int money1=0,money2 = 0;money1=b*2*5*8/4*3;if (a==0) {money2=money1;} if (a==1) {money2=money1+8;} if (a==2) {money2=money1+2*8*95/100;} if (a==3) {MONEY2=MONEY1+3*8/10;} if (a==4) {MONEY2=MONEY1+4*8/5;} if (a==5) {MONEY2=MONEY1+5*8/4;} if (a==6) {MONEY2=MONEY1+8+5*8/4;} if (a==7) {MONEY2=MONEY1+3*8/10+4*8/5;} if (a==8) {MONEY2=MONEY1+2*4*8/5;} if (a==9) {MONEY2=MONEY1+4*8/5+5*8/4;} System.out.println ("Amount:" +money2);}}
Experiment:
Classroom Training Books