当前位置:网站首页>2. Average length of words
2. Average length of words
2022-04-23 06:08:00 【linsa_ pursuer】
Each sentence consists of multiple words , The length of each word in the sentence may be different , Give the average word length of the whole sentence
package com;
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println(avg(s.nextLine()));
}
public static String avg(String words){
String[] arr = words.split(" ");
int sum = 0;
for(int i=0;i<arr.length;i++){
sum += arr[i].length();
}
return (new BigDecimal(String.valueOf(sum))).divide(new BigDecimal(String.valueOf(arr.length)), 2, BigDecimal.ROUND_HALF_UP).toPlainString();
}
}
Such as :
Input :Who Love Solo
Output :3.67
版权声明
本文为[linsa_ pursuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533259961.html
边栏推荐
- Preparedstatement prevents SQL injection
- JSP syntax and JSTL tag
- SQL injection
- JDBC connection database
- Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
- In depth understanding of the relationship between dncblevel and noise denoising in the paper
- 图解numpy数组矩阵
- Custom exception class
- JDBC operation transaction
- Pytorch learning record (IX): convolutional neural network in pytorch
猜你喜欢

List segmentation best practices

线性代数第三章-矩阵的初等变换与线性方程组
![Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning](/img/21/4bc94fe29f416c936436c04fc16fa8.png)
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning

You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it

LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising

Algèbre linéaire chapitre 2 - matrice et son fonctionnement

IO multiplexing of 09 redis
![Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi](/img/1b/4eea05e2634780f45b44273d2764e3.png)
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi

String notes

Latex quick start
随机推荐
自动控制(韩敏版)
Shansi Valley P290 polymorphism exercise
卡尔曼滤波与惯性组合导航
Practical operation - Nacos installation and configuration
Pytorch learning record (IV): parameter initialization
Chapter 4 of line generation - linear correlation of vector systems
MySQL basic madness theory
Anaconda
Custom exception class
Numpy common function table sorting of data processing
Dva中在effects中获取state的值
Pytorch学习记录(十二):学习率衰减+正则化
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Pytorch——数据加载和处理
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
JSP syntax and JSTL tag
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
A general U-shaped transformer for image restoration
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images