随机数组&大数相加
随机生成10个数,填充一个数组,然后用消息框显示数组内容,接着计算数组元素的和,将结果也显示在消息框中
一, 设计思路:
先生成随机数数组,再将数组保存在一个字符串中,然后将数组各数字加和,
二, 程序流程图

三, 源程序代码
import javax.swing.JOptionPane;
public class ArraySum
{
public static void main(String[] args)
{
int[] array=new int[10];//定义一个数组,长度为10。
int result=0; //定义一个变量初值为0。
String output="";
//随机生成一个100以内的数,填充数组。
for(int i=0;i<array.length;i++)
array[i]=(int)(Math.random()*100);
//将数组元素输出。
output+="随机生成的十个数是:"+"\n";
for(int i=0;i<array.length;i++)
output+=array[i]+" ";
output+="\n";//换行
//将数组元素相加。
for(int i=0;i<array.length;i++)
result+=array[i];
output+="十个数相加等于:"+"\n"+result;
//以消息框的形式输出。
JOptionPane.showMessageDialog(null, output,
"输出",JOptionPane.INFORMATION_MESSAGE);
}
}
四, 结果截图



大数相加:
随机数组&大数相加的更多相关文章
- java-两个大数相加
题目要求:用字符串模拟两个大数相加. 一.使用BigInteger类.BigDecimal类 public static void main(String[] args) { String a=&qu ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- Linux C/C++ 编程练手 --- 大数相加和大数相乘
最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...
- 基于visual Studio2013解决C语言竞赛题之1077大数相加
题目 解决代码及点评 /************************************************************************/ /* ...
- JavaScript中大数相加的解法
一.两个大正整数字符串相加 在JavaScript中,数值类型满足不了大数据容量计算,可以用字符串进行操作 function add(strNum1, strNum2) { // 将传进来的数字/数字 ...
- Java实现大数相加、相乘(不使用BigInteger)
大数相加: package algorithm; //使用BigInteger类验证 import java.math.BigInteger; public class BigAdd { public ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- Poj 2602 Superlong sums(大数相加)
一.Description The creators of a new programming language D++ have found out that whatever limit for ...
- JavaScript 实现彩票中随机数组的获取
1.效果图: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
随机推荐
- hdu5412——CRB and Queries
1.题目大意:区间第k大,单点修改 2.随便搞搞就好了= =,树套树或主席树,我写的很丑 #include <cstdio> #include <cstdlib> #inclu ...
- 两款基于Jquery的图表插件
一.EasyPieChart 页面加载时,运行initPieChart()函数,调用easyPieChart()函数,显示出图表. 代码: var initPieChart = function() ...
- Laravel 5.1 文档攻略 —— Eloquent:模型对象序列化
在写api的时候,数据一般是以json格式进行传输的,没有对象可以直接使用.这个时候,对数据的序列化转换就很重要,Eloquent提供了很方便的方法和约定,不仅可以转换,还可以控制里面的键值. 基本用 ...
- opencv高斯背景建模
#include <iostream> #include <string> #include <opencv2/opencv.hpp> int main(int a ...
- OpenCV加载图像并显示
从文件中读取一直一张图片,并加载出来 代码: #include "stdafx.h" #include "iostream" using namespace s ...
- win7 ubuntu 14.04双系统安装
安装win7和linux双系统,一般先安装win7,后安装linux,本片就是指在安装好win7的情况下,安装ubuntu. 准备材料: EasyBCD软件 ubuntu14.04iso镜像文件,64 ...
- Github Bash
第一步生成密钥:ssh-keygen -C 'your@email.address' 第二步验证结果:ssh -T git@github.com 第三步克隆:git clone https://git ...
- spring mvc 避免IE执行AJAX时,返回JSON出现下载文件
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 --> <bean id="mappingJacksonHttpMessageConverter" c ...
- iOS关于UILabel 基本属性 背景图片 背景色
[代码] iOS关于UILabel 基本属性 背景图片 背景色 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
- HTML5之sessionStorage
http://www.css88.com/archives/tag/sessionstorage http://blog.csdn.net/qxs965266509/article/details/1 ...