我如何才能获得额外的数字? [英] How do I only get the extra numbers to print?

查看:64
本文介绍了我如何才能获得额外的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加数组中的额外数字。我不能超过100.所以我的代码有101,83.107和90.我的输出需要显示8,因为这是额外超过100的总和。我的代码设置在for循环中。



我尝试过:



I'm trying to add up the extra numbers that are in my array. I can't exceed 100. so my code has 101, 83.107, and 90. My output needs to show 8 because that's the sum of the extra exceeding 100. I have my code set up in a for loop.

What I have tried:

import java.util.Scanner;

public class SumOfExcess {
   public static void main (String [] args) {
      final int NUM_VALS = 4;
      int[] testGrades = new int[NUM_VALS];
      int i = 0;
      int sumExtra = 0;

      testGrades[0] = 101;
      testGrades[1] = 83;
      testGrades[2] = 107;
      testGrades[3] = 90;

      for(i = 0; i < NUM_VALS, i++)
      {
         if (testGrades > 100)
      
      }   

      System.out.println("sumExtra: " + sumExtra);

      return;
   }
}

推荐答案

学会正确缩进代码,显示其结构,有助于阅读和理解。

Learn to indent properly your code, it show its structure and it helps reading and understanding.
import java.util.Scanner;

public class SumOfExcess {
    public static void main (String [] args) {
        final int NUM_VALS = 4;
        int[] testGrades = new int[NUM_VALS];
        int i = 0;
        int sumExtra = 0;

        testGrades[0] = 101;
        testGrades[1] = 83;
        testGrades[2] = 107;
        testGrades[3] = 90;

        for(i = 0; i < NUM_VALS, i++)
        {
            if (testGrades > 100)

                System.out.println("sumExtra: " + sumExtra);

            return;
        }
    }



专业程序员的编辑器具有此功能以及其他功能,例如括号匹配和语法高亮。

Notepad ++ Home [ ^ ]

ultraedit [ ^ ]



在您的情况下,它表明缺少} 并且循环中可能缺少一些代码。


Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]

In your case, it show that there is a missing } and some code is probably missing in the loop too.


这篇关于我如何才能获得额外的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆