Вы можете легко сделать это с помощью vanilla js.
Просто добавьте текстовый узел в документ. Он будет экранирован браузером.
var escaped = document.createTextNode("<HTML TO/ESCAPE/>")
document.getElementById("[PARENT_NODE]").appendChild(escaped)
Предположим, у вас есть список GPA, найдите среднее значение, которое вы можете использовать в следующих документах в Java 8
List<Double> gpas = Arrays.asList(1.0,2.0,3.0,4.0);
double average = gpas.stream()
.collect(Collectors.averagingDouble(value -> value.doubleValue()));
System.out.println(average);
Я пробовал с Java-8
DoubleSummaryStatistics statistic = IntStream.range(0, 8)
.boxed() //int to Integer
.collect(Collectors.summarizingDouble(i -> Math.random() * 4.1)); //collect to statistic
System.out.println(statistic.getAverage());
Вы получите среднее значение из 8 результатов из Math.random()*4.1
Вы можете использовать статическую переменную для отслеживания всех GPA (внутри класса Student) и затем, наконец, вернуть его.
class Student{
static double total;
String semesterGPA(){
.
.
//just add the GPA to the total before return statement
total += myRandomNumber;
//return statement
}
String averageGPA()
{
double averageGPA = total / 9;
//return statement including averageGPA
}
}