c# - C#模数方程返回错误值
问题描述
var newPosition = (position - key) % alphabet.Length;
当 position 是 66,key 是 7964 并且 alphabet.length = 91,newPosition 是-72,即使它应该是 19。为什么?
解决方案
((position - key) % alphabet.Length + alphabet.Length) % alphabet.Length
做到了
推荐阅读
- java - Android 下载 AsyncTask 冻结了我的应用很长时间
- python - 从单独的文件python导入函数
- ruby-on-rails - 无法让 Bootstrap 在 Ruby on rails 应用程序中工作
- angular - 打字稿转换为数字有效,但现在不行
- reactjs - 有没有办法使用 api 映射我的城市阵列上的城市并渲染来自阵列上所有城市的信息?
- php - 如何在浏览器中从我的数据库中显示 PDF 文件?
- r - 如何在 R 中的数据框中对不同日期的数据进行不同的标准化?
- firebase - Firebase 数据库:用户是否每次都下载整个数据库?
- c# - c# 带有 mysqldatabase 的应用程序使用大量 ram
- intellij-idea - 如何做箭头和不等于这样