java - I want to get pick out a value scanned from a method and get sum of 3 instances of the method -


here code

import java.util.arraylist; import java.util.scanner; public class recyclebeta {  public static void main(string[] args) {     system.out.println("insert bottles pant a");     system.out.println(bottlelist(1));     system.out.println();     system.out.println("insert bottles pant b");     system.out.println(bottlelist(2));     system.out.println();     system.out.println("insert bottles pant c");     system.out.println(bottlelist(3));  }      public static string bottlelist(int args) {          scanner bottler = new scanner(system.in);          int count = 0;          arraylist<string> bottles = new arraylist<string>();          system.out.println("press 1 , enter each bottle, end 0");          string cont;          while (!(cont = bottler.next()).equals("0"))         {                    bottles.add(cont);             count++;         }         return ("you have inserted " + count + " bottles");       } } 

i want add multiplier each of bottlelist(1),(2) , (3).

so "count" value in bottlelist(1) multiplied 1.5, bottlelist(2) 2.0 , bottlelist(3) 3.0.

i sum total amount of bottles scanned 3 instances in main method. @ stage though, i'm clueless on how without creating 3 different method call upon, seems bit redundant. if have suggestions improve code bit, i'm ears (i'm 4 weeks programming java).

you don't use "args" parameter pass bottlelist method.

change type of "args" int double, pass in 1.5, 2, 3 add @ end of method.

return ("you have inserted " + (count * args) + " bottles"); 

unless i've misunderstood you're trying do. change name of args meaning, "multiplier".


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -