代码-java 难题 求大侠帮忙。小弟谢过了

问题描述

java 难题 求大侠帮忙。小弟谢过了

求大虾帮帮忙。 由于我底子薄,最好能用java 代码帮我解决下。
各组 ,每组有不同月份的业绩。

一共两个for循环,

for (i = 0; i<=组 ; i++)
{
for(j = 0 ;j< = 月份; j++)
{
这里是循环到月份 的业绩。取得到当月业绩。
}

}
例如:一共四个组,四个月份。按月份划分, 我要算出每个月的所有组业绩之和。

一组:一月 100 。二月200 。三月300. 四月。400
二组:100 200 300 400
三组:100 200 300 400
四组 同上, 最终算出1月 400 。二月800 。三月1200.。。

最后得出一个list 或者 数组都可以,长度为总月份。里面包含每个月的业绩。可能用到二维数组,或者HashMap

问题: 怎么在上面公式里追加计算。。

解决方案

组数确定不?如果确定的话,可以考虑这种简单的做法:

 // 总共有四组,每一组有四个月的业绩数据:100,200,300,400
        int A[][] = { { 100, 200, 300, 400 }, { 100, 200, 300, 400 }, { 100, 200, 300, 400 }, { 100, 200, 300, 400 } };
        int B[] = new int[4];
        for (int i = 0; i < A.length; i++) {// 遍历组数
            // 目标:计算出每个月的总业绩
            B[i] = A[0][i]
                    + A[1][i]
                    + A[2][i]
                    + A[3][i];
        }
        for (int i = 0; i < B.length; i++) {
            System.out.println("各月的总业绩:"
                    + B[i]);
        }

测试过了,同样能实现。

解决方案二:

这里是测试结果。如果不是你想要的,可以留言。希望能够帮到你。

解决方案三:

组数,月份都不确定,十二月以内

解决方案四:

public class SumPerformanceOfMonth
{
//四个月的业绩集合
private static List mpList;

static
{
    mpList = new ArrayList<MouthPerformance>();
    for (int i = 1; i < 5; i++)
    {
        //每组业绩
        Map<String, Integer> performance = new HashMap<String, Integer>();
        performance.put("一组", 100 * i);
        performance.put("二组", 100 * i);
        performance.put("三组", 100 * i);
        performance.put("四组", 100 * i);
        mpList.add(new MouthPerformance(i + "月", performance));
    }
}

public static void main(String[] args)
{

    Map<String, Integer> countPerformance = new HashMap<String, Integer>();
    //遍历四个月的业绩信息
    for (int i = 0; i < mpList.size(); i++)
    {
        MouthPerformance m = (MouthPerformance)mpList.get(i);
        Map<String, Integer> mp = m.getPerformance();
        int sum = 0;
        for (String s : mp.keySet())
        {
            sum += mp.get(s);
        }
        countPerformance.put(m.getMouth(), sum);
    }
    System.out.println(countPerformance);
}

}

//每月业绩
class MouthPerformance
{
//月份
private String mouth;

//每组业绩
private Map<String, Integer> performance;

MouthPerformance(String mouth, Map<String, Integer> performance)
{
    this.mouth = mouth;
    this.performance = performance;
}

/**
 * @return 返回 mouth
 */
public String getMouth()
{
    return mouth;
}

/**
 * @param 对mouth进行赋值
 */
public void setMouth(String mouth)
{
    this.mouth = mouth;
}

/**
 * @return 返回 performance
 */
public Map<String, Integer> getPerformance()
{
    return performance;
}

/**
 * @param 对performance进行赋值
 */
public void setPerformance(Map<String, Integer> performance)
{
    this.performance = performance;
}

}


解决方案五:

业绩是在那个for循环里才出现的。我的问题说的有些模糊,必须在上面两个for循环基础上做。

解决方案六:

int a[][]={100,200,300,400;100,200,300,400;100,200,300,400;100,200,300,400};
int b[]=new int[4];
for(int i=0;i<3;i++){
b[i]=0;
}
for (i = 0; i<4 ; i++)
{
for(j = 0 ;j< 4; j++)//注意不是小于等于
{
b[i]+=a[i][j];
}
}

解决方案七:

public class Results {
/*/
* 月份和每个组的成绩都不确定
*/
public static void main(String[] args) {

//总业绩二维数组,不知道你看得懂吧
int[][] performance={{100,200,300,400},{100,200,300,400},{100,200,300,400},{100,200,300,400}};
//月份数
int[] month={1,2,3,4};
for(int i=0;i<month.length;i++){
System.out.println(i+1+"月"+"业绩为"+sum(i, performance));
}

}
/*/
 * 传入月份数和总业绩,返回每个月的业绩
 */
public static int sum(int month,int[][] performance){
    int sum=0;
    int[] results = null;
    for(int i=0;i<performance.length;i++){
         results=performance[i];
         sum+=performance[i][month];
    }
    return sum;
}

}
月份数,还有总业绩的二维数组都可以随意变换的.

解决方案八:

public class Results {
/*/
* 月份和每个组的成绩都不确定
*/
public static void main(String[] args) {

//总业绩二维数组,不知道你看得懂吧
int[][] performance={{100,200,300,400},{100,200,300,400},{100,200,300,400},{100,200,300,400}};
//月份数
int[] month={1,2,3,4};
for(int i=0;i<month.length;i++){
System.out.println(i+1+"月"+"业绩为"+sum(i, performance));
}

}
/*/
 * 传入月份数和总业绩,返回每个月的业绩
 */
public static int sum(int month,int[][] performance){
    int sum=0;
    int[] results = null;
    for(int i=0;i<performance.length;i++){
         results=performance[i];
         sum+=performance[i][month];
    }
    return sum;
}

}
月份数,还有总业绩的二维数组都可以随意变换的.

解决方案九:

public class Results {
/*/
* 月份和每个组的成绩都不确定
*/
public static void main(String[] args) {

//总业绩二维数组,不知道你看得懂吧
int[][] performance={{100,200,300,400},{100,200,300,400},{100,200,300,400},{100,200,300,400}};
//月份数
int[] month={1,2,3,4};
for(int i=0;i<month.length;i++){
System.out.println(i+1+"月"+"业绩为"+sum(i, performance));
}

}
/*/
 * 传入月份数和总业绩,返回每个月的业绩
 */
public static int sum(int month,int[][] performance){
    int sum=0;
    int[] results = null;
    for(int i=0;i<performance.length;i++){
         results=performance[i];
         sum+=performance[i][month];
    }
    return sum;
}

}
月份数,还有总业绩的二维数组都可以随意变换的.

解决方案十:

public class Results {
/*/
* 月份和每个组的成绩都不确定
*/
public static void main(String[] args) {

//总业绩二维数组,不知道你看得懂吧
int[][] performance={{100,200,300,400},{100,200,300,400},{100,200,300,400},{100,200,300,400}};
//月份数
int[] month={1,2,3,4};
for(int i=0;i<month.length;i++){
System.out.println(i+1+"月"+"业绩为"+sum(i, performance));
}

}
/*/
 * 传入月份数和总业绩,返回每个月的业绩
 */
public static int sum(int month,int[][] performance){
    int sum=0;
    int[] results = null;
    for(int i=0;i<performance.length;i++){
         results=performance[i];
         sum+=performance[i][month];
    }
    return sum;
}

}
月份数,还有总业绩的二维数组都可以随意变换的.

时间: 2024-08-18 15:50:48

代码-java 难题 求大侠帮忙。小弟谢过了的相关文章

c语言-C语言题程序第二个输出结果是124还是125呢?求大侠帮忙解释

问题描述 C语言题程序第二个输出结果是124还是125呢?求大侠帮忙解释 #includeint change(int *data){ return (*data)++;}main(){ int data=123; change(&data); printf(""%ddata); data=change(&data); printf(""%d""data); printf(""n"");}V

c语言-C语言将两个递增有序单链表归并为一个降序的单链表,求大侠帮忙看看

问题描述 C语言将两个递增有序单链表归并为一个降序的单链表,求大侠帮忙看看 #include #include #define N 8 typedef struct list { char c; struct list *next; } SLIST; SLIST *creat(char *a) { SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i { q=(SLIST *)malloc(sizeof(SLI

c#-C# IF语句求大侠帮忙了

问题描述 C# IF语句求大侠帮忙了 Tb_blacklist是数据库里的一个表然后下面是我写的IF语句这明显是错的,新手求帮忙 解决方案 c#--if语句c#中if语句C# bool true false 操作符重载,用在 if while等语句中 解决方案二: 参考这个: OracleConnection conn = null; try { conn = GetOracleConnection(); conn.Open(); OracleCommand cmd = new OracleCo

c语言-求大侠帮忙:C语言程序设计---编程题(以下所有题目程序应是非递归的)

问题描述 求大侠帮忙:C语言程序设计---编程题(以下所有题目程序应是非递归的) 编写一个函数insert(s1,s2,ch),实现在字符串s1中的指定字符ch位置处插入字符串s2. 学校工会组织活动,要求有8名教师参加,这8名教师将分别从A学院3名教师.B学院5名教师.C学院6名教师中任意抽取,且其中必须有B学院的教师参加,请编程输出所有可能的方案 已知在C盘根目录下存有文本文件"file1.txt",编程统计文件"file1.txt"中每个字母字符和每个数字字符

sql server创建存储过程初始化失败,不知道为什么,求大侠帮忙看看

问题描述 sql server创建存储过程初始化失败,不知道为什么,求大侠帮忙看看 CREATE PROCEDURE p_getLogFilter @account VARCHAR(20), @split VARCHAR(10) AS BEGIN DECLARE @splitlen INT, @au_id CHAR(50), @s VARCHAR(MAX), @cform VARCHAR(255), @dbname VARCHAR(200), @sqlstr NVARCHAR(MAX) --获取

java代码-java程序 求大神指导

问题描述 java程序 求大神指导 1.编写程序删除"C:Documents and SettingsAdministratorLocal SettingsTemporary Internet Files" 和"C:WINDOWSDownloaded Program Files"下所有的TMP文件和JS文件:

easyui tree我用java写的json,为什么我的第一级树出来了,然后其他的树都放到了第一级下的子级其他子级下面都是空的,求大侠帮忙

问题描述 publicvoidgetTree(){List<Tmenu>list=permissionService.findTree();List<Tree>treeList=newArrayList<Tree>();List<Tree>treeListChildren=newArrayList<Tree>();List<Tree>treeListChildrenGrandson=newArrayList<Tree>()

ASPX中不能执行JS函数,提示未定义,真要命,求大侠帮忙

问题描述 <%@PageLanguage="C#"AutoEventWireup="true"CodeFile="HTMLPage.aspx.cs"Inherits="HTMLPage"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-

求大侠帮忙指点一下,用C#编写的股票组合;

问题描述 各位好,通过筛选股票的程序,筛选出52只股票,但是现在想编写一个在一定量资本的情况下选出4只目标股票,并计算出各种股票的最佳数量,目前有的数据为:每只股票的价格,每只股票的收益率,每只股票可能面临的亏损值:我目前的操作分为两步走:1.从52只股票中随机构建组合,每个组合包含4只股票,组合以后的数据约22万条:思路:使用的递归算法,构建这个组合的数据比较快,大概10分钟可以完成:2.计算每个组合的最优购买数量,然后并计算所有组合的最优数量,从而得到52只股票的最优组合.思路:先计算出在一