class B {
public static void main(String a[])
{
int x;
String aa[][]= new String[2][2];
aa[0]=a;
x=aa[0].length;
for(int y=0;y<x;y++)
System.out.print(" "+aa[0][y]);
}
}
Run Code Online (Sandbox Code Playgroud)
并且命令行调用是
>java B 1 2 3
而且选项是
1.)0 0
2.)1 2
3.)0 0 0
4.)1 2 3
我告诉第二个选项是正确的,因为数组是声明的[2][2],所以它不可能是这样的[0][2].但是,回答是1 2 3.任何人解释一下,这是怎么发生的?
我有一个包含此内容的Java字符串:
Response: Success
Message: Extension Status
Exten: 1234
Context: from-sip
Hint: DS/5678
Status: 9
Run Code Online (Sandbox Code Playgroud)
我想搜索这个字符串键"Exten:"和"Status:",并获取相应的值,即"1234"和"9".这样做的最佳方法是什么?
我希望程序获取用户的身高和体重,然后将其输入到bmi公式中,然后输出结果.
高度问题工作正常,但是当您在重量问题中输入一个数字并按下回车键时,它只会换行.输入另一个数字后,它会将其设置为bmi并打印出来.
#include<stdio.h>
int main()
{
int h, w, bmi;
printf("What is your height (in inches)? ");
scanf("%d", &h);
printf("What is your weight? ");
scanf("%d", &w);
bmi = (w/(h*h))*703;
scanf("%d", &bmi);
printf("\t\tBMI\n");
printf("US: %d\n", bmi);
}
Run Code Online (Sandbox Code Playgroud) 我正在解决来自 hackerrank 的Sam 和子串问题。它基本上是查找具有所有整数的字符串的所有子字符串的总和。
\n\n\n萨曼莎和山姆正在玩数字游戏。给定一个数字作为字符串,没有前导零,确定该字符串的子字符串的所有整数值的总和。
\n
\n\n给定一个字符串形式的整数,将其所有转换为整数的子字符串相加。由于数字可能会变大,因此返回模 10\xe2\x81\xb9\xc2\xa0+\xc2\xa07 的值。
\n
\n\n例子:
\nn = \'42\'
\n\n这里n是一个字符串,它具有三个整数子字符串:4、2 和 42。它们的和是 48,48 模 10\xe2\x81\xb9\xc2\xa0+\xc2\xa07 = 48。
\n
\n\n在下面的编辑器中完成 substrings 函数。\nsubstrings 具有以下参数:\nstring n: 整数的字符串表示形式\n返回
\n
int: n中所有子字符串的整数值之和,模 (10\xe2\x81\xb9 + 7)
\n我尝试使用记忆化来遵循递归自上而下的动态问题解决方案:
\nfrom functools import cache\n\ndef substrings(n):\n @cache\n def substrSum(curIndex):\n if curIndex == 0: return int(n[0])\n return substrSum(curIndex-1)*10 + int(n[curIndex]) * (curIndex+1)\n \n totalSum = …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
class Course{
public:
string name;
int pars[];
Course();
};
class Runs{
public:
Course course; <- Error
int scores[];
Runs();
};
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用这些类从格式错误的文件中读取行。为什么我不能在类中使用类?