Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 阵列的频率分布_Java - Fatal编程技术网

Java 阵列的频率分布

Java 阵列的频率分布,java,Java,您好,我正在尝试获取文本字体大小和颜色数组的频率,当我有字符串时,我计算频率,我想根据其大小的总体值更改单词和颜色的大小,我尝试除以frequency/average*10但给我空值,但在我的计算器上它给我ie,80/100*10=8,索引为8,字体大小为180 有人能帮我吗 private static int[] fontWeight = { 40, 60, 80, 100, 120, 140, 160,180 }; private static Color[] Colors = { Col

您好,我正在尝试获取文本字体大小和颜色数组的频率,当我有字符串时,我计算频率,我想根据其大小的总体值更改单词和颜色的大小,我尝试除以
frequency/average*10
但给我空值,但在我的计算器上它给我ie,80/100*10=8,索引为8,字体大小为180

有人能帮我吗

private static int[] fontWeight = { 40, 60, 80, 100, 120, 140, 160,180 };
private static Color[] Colors = { Color.blue, Color.cyan, Color.yellow, Color.green, Color.red,
        Color.orange, Color.pink,Color.pink  };
//主要

  for (String str: wordList) {


            int wordFreq = randWord.getFrequency();//assume 80 comes here
            int fontSize = getFontSize(wordFreq);
            Font font = new Font(Font.SANS_SERIF, Font.ITALIC, fontWeight [fontSize ]);
            graphics.setFont(font);
            graphics.setColor(Colors[fontSize]);
            FontMetrics fm = graphics.getFontMetrics();

            graphics.drawString(randWord.getWord() + "", x, y);
            }
//方法

  private static int getFontSize(int freq) {

    int newFont = (int) (freq/100)*10;

    if (newFont >= 5) newFont = 6;
    // if(newFont<2)
    // newFont = 1;
    System.out.println("freq " + freq + " font index" + newFont + "  font size "
            + fontWeight[newFont]);

    return newFont;
}
private static int getFontSize(int freq){
int newFont=(int)(频率/100)*10;
如果(newFont>=5)newFont=6;

//如果(newFont整数除法的行为不同,如果分子小于分母,则结果为0。例如,80/100返回0。您要做的是将分子与10相乘,然后将其除法

int newFont = (int) (freq/100)*10;
应改为

int newFont = (int) (freq*10 / 100);