How to read list of numbers with readLine method in java? -
this question exact duplicate of:
i want ask question readline()
method. project reading numbers in list
separated spaces , calculate arithmetic mean remainder discarding lowest , biggest numbers. try way read number of them incorrect. how can read numbers readline()
method in java ?
p.s : program should working acm
libary(console program)
int [] inputarray ; ---> helpful me ?
thanks help.
import java.text.decimalformat; import java.util.scanner; import acm.program.consoleprogram; public class ccc extends consoleprogram { public static void main(string[] args) { /* * data input. */ scanner kb = new scanner(system.in); /* * declare array store judge's scores. */ double[] scores = new double[8]; /* * declare variables lowest , highest scores. */ double lowestscore = integer.max_value; double highestscore = integer.min_value; /* * read 7 judge's scores. */ (int = 0; < 7; i++) { system.out.println(string.format("judge score #%d: ", + 1)); scores[i] = kb.nextdouble(); /* * compare current score lowest , highest scores. */ if (scores[i] < lowestscore) { lowestscore = scores[i]; } if (scores[i] > highestscore) { highestscore = scores[i]; } } /* * sum scores, except lowest , highest scores. */ double total = 0.00; (int = 0; < 7; i++) { if (scores[i] != lowestscore && scores[i] != highestscore) { total = total + scores[i]; } } /* * display output. */ decimalformat df = new decimalformat("0.00"); system.out.println("total points received: " + df.format(total)); system.out.println("arithmetic mean : " + df.format(total / 7)); }
}
this code ,ı asked stackedoverflow's people how solve problem couldn't solve .in program , should number list user.for example; user writes list " 11 23 4 55 66 7"(there spaces between numbers).my program should discard biggest , lowest numbers calculate arithmetic mean.i scanner method succesfully,as can see teacher wants me write program acm libary(consoleprogram).this program runs java application when want run in java applet,i can't it.
thanks , understanding.
are there me ?
if have use bufferedreader.readline()
, need to
- trim line , split values
- use
long.parseparse or
double.parsedouble
approriate. - place each value list
- sort list.
- discard highest , lowest
- sum values left
- divide size of list average.
Comments
Post a Comment