java - How Can i Use The Values Of The Int in The Scanner -


            int cmc = 279;             int bdm = 326;             int cp = 177;             int cb =  228;             int cr = 190;             int pc = 43;             int ccs = 24;             int ce = 26;             int fm = 20;             int originalpricebake ;              scanner bakeorder1 = new scanner(system.in);             int order1;                          system.out.print("\nenter 1st item order:");             order1 = bakeorder1.nextint();             scanner bakeorder2 = new scanner(system.in);             int order2;                          system.out.print("\nenter 2nd item order:");             order2 = bakeorder2.nextint();             scanner bakeorder3 = new scanner(system.in);             int order3;                          system.out.print("\nenter 3rd item order:");             order3 = bakeorder3.nextint();             scanner bakeorder4 = new scanner(system.in);             int order4;                          system.out.print("\nenter 4th item order:");             order4 = bakeorder4.nextint();             scanner bakeorder5 = new scanner(system.in);             int order5;                          system.out.print("\nenter 5th item order:");             order5 = bakeorder5.nextint();              originalpricebake = order1 + order2 + order3 + order4 + order5;             system.out.print("\nthe current price: " + originalpricebake); 

how can use integer values on top when scan user input order? when got user input equation made @ bottom of code

use array store values , access using loop.

    int order;     int price=0;     scanner scan = new scanner(system.in);     system.out.print("enter how many orders: ");     order = integer.parseint(scan.nextline());       //create integer array store input      int bakeorder[] = new int[order];     //int originalbakeprice[] = new int[order];     for(int i=0;i<order;i++)     {         system.out.print("enter order " + (i+1) + " : ");             bakeorder[i] = integer.parseint(scan.nextline());              price +=bakeorder[i];     }             system.out.println(price); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -