出于某种原因,当我尝试打印一个(11.3)时,此代码为数组中的最高值打印三个值.有人可以向我解释为什么这样做吗?
谢谢.
import java.util.Scanner;
public class Slide24
{
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
double[] decMax = {-2.8, -8.8, 2.3, 7.9, 4.1, -1.4, 11.3, 10.4,
8.9, 8.1, 5.8, 5.9, 7.8, 4.9, 5.7, -0.9, -0.4, 7.3, 8.3, 6.5, 9.2,
3.5, 3, 1.1, 6.5, 5.1, -1.2, -5.1, 2, 5.2, 2.1};
double total = 0, avgMax = 0;
for (int counter = 0; counter < decMax.length; counter++)
{
total += decMax[counter];
}
avgMax = total / …Run Code Online (Sandbox Code Playgroud) 我有一个是或否的问题和答案.如果答案是肯定的,我想问另一个是或否的问题.我的导师希望我们使用charAt(0)作为答案的输入.
是否可以在另一个语句中使用switch语句(如嵌套的if语句)?
提前致谢.
编辑:这是我的伪代码=的示例
display "Would you like to add a link (y = yes or n = no)? "
input addLink
switch (link)
case 'y':
display "Would you like to pay 3 months in advance " + "(y = yes or n = no)?"
input advancePay
switch(advPay)
case 'y':
linkCost = 0.10 * (3 * 14.95)
case 'n'
linkCost = 14.95
case 'n'
linkCost = 0.00
Run Code Online (Sandbox Code Playgroud) 我正在尝试将莫尔斯代码转换为文本.
我有两个文本文件用于此问题.morseCode.txt:我有一个我读过的文件,其中包含相应的字母和相应的摩尔斯电码.
morse.dat:包含摩尔斯电码加密消息的文件
我能够正确读取第一个文件然后存储到单独的数组中.我通过打印字母和数组莫尔斯代码来测试它,发现它确实按顺序存储它.
我在阅读第二个文件时遇到问题.这是morseCode.txt键:
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
. .-.-.-
, …Run Code Online (Sandbox Code Playgroud) /*This is a program that calculates Internet advertising rates based on what features/options you choose.
*
*
*/
import java.util.Scanner;
public class InternetAdvertising
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int numberOfWords;
//I assigned 0 values to both as Eclipse suggested
float textCost = 0;
float linkCost = 0;
float graphicCost;
//<=25 words is a flat fee of $.40 per word plus Base fee of $3.00
final float TEXT_FLAT_FEE = 0.40F;
final float TEXT_BASE_FEE = …Run Code Online (Sandbox Code Playgroud) 如何在Perl中找到两个不同数组的所有值的总和?
@array1 = (1, 2, 3);
@array2 = (10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
@sumofarray1and2 = ?
所以我想我可以在这里做两件事.我可以做两个foreach循环并添加内容,@array1然后@array2首先得到两者的总和.