小编Hea*_*r T的帖子

如果检查有多少条件

如果检查有多少条件?例如,

if(a==1 && b==1 && c==1 && ... && n==1)
Run Code Online (Sandbox Code Playgroud)

我知道这可能只是通过嵌套ifs来解决,然后它不会是一个多少问题.但坦率地说,我很好奇,似乎无法找到需要多少.

另外,既然我已经引起了你的注意,那么效率之间是否存在差异

if(a==1 && b ==1)
Run Code Online (Sandbox Code Playgroud)

if(a==1)
    if(b==1)
Run Code Online (Sandbox Code Playgroud)

java if-statement conditional-statements

5
推荐指数
2
解决办法
4634
查看次数

从随机数组中拉出最小值和最大值以显示

所以,就像标题所说我需要从我创建的数组中提取最小值和最大值,利用随机数生成器来填充它.我觉得这可能是我需要使用的Math类操作符(IE,math.floor和math.ceiling),但如果是这样的话,我不太确定如何将它们与数组一起使用.我想底线是我不太明白数组如何工作,即使我已经完成了几个使用它们的任务.这是我到目前为止所拥有的(我必须在列表框中显示所有值并给出此分配的平均值和最小值/最大值)

 private void button1_Click(object sender, EventArgs e)
    {
    int SIZE = 10;
    int[] nummers = new int[SIZE];
    Random rand = new Random();
    int total = 0;

    for (int index = 0; index < nummers.Length; index++)
    {
        nummers[index] = rand.Next(1, 100);

    }
    foreach (int value in nummers)
    {
        total += value;
        listBox1.Items.Add(value);
    }
    total/= 10;
    label3.Text = total.ToString("d");
Run Code Online (Sandbox Code Playgroud)

c# arrays random max min

1
推荐指数
1
解决办法
2214
查看次数

删除标点符号在Java中不能使用字符串替换

所以,我要做的是编译一个单词列表,没有8个单独的字典单词列表中的重复.一些字典中有标点符号来分隔单词.以下是我所涉及的标点符号删除.我已经尝试了几种不同的解决方案,我发现堆栈溢出有关正则表达式,以及我在代码中留下的那个.出于某种原因,他们都没有从源词典中删除标点符号.有人可以告诉我它是什么我在这里做错了,可能还有如何修复它?我很茫然,有一个同事检查它,他说这应该也可以.

int i = 1;
boolean checker = true;
Scanner inputWords;
PrintWriter writer = new PrintWriter(
        "/home/htarbox/Desktop/fullDictionary.txt");
String comparison, punctReplacer;

ArrayList<String> compilation = new ArrayList<String>();



while (i <9)
{
inputWords = new Scanner(new File("/home/htarbox/Desktop/"+i+".txt"));
    while(inputWords.hasNext())
    {
        punctReplacer = inputWords.next();
        punctReplacer.replaceAll("[;.:\"()!?\\t\\n]", "");
        punctReplacer.replaceAll(",", "");
        punctReplacer.replaceAll("\u201C", "");
        punctReplacer.replaceAll("\u201D", "");
        punctReplacer.replaceAll("’", "'");

        System.out.println(punctReplacer);
        compilation.add(punctReplacer);
    }
    }
inputWords.close();
}
i = 0;
Run Code Online (Sandbox Code Playgroud)

java string arraylist replaceall

1
推荐指数
1
解决办法
525
查看次数

getNameCount() 实际上算什么?

我的问题有两部分 - 首先,标题到底是什么 - Path.getNameCount() 方法实际计数的是什么?在Eclipse中选择方法时,我阅读了它附带的小弹出信息,我认为这是一个合适的用法。我使用它创建的这个方法在运行时返回 5 作为 int 。其次,我想要做的是返回目标目录中有多少文件,以便我可以运行另一种方法,我必须以适当的次数检索文件名。如果 getNameCount() 方法不适合此功能,您是否有任何关于如何完成相同目的的建议?

//Global Variable for location of directory
Path dir = FileSystems.get("C:\\Users\\Heather\\Desktop\\Testing\\Testing2");
//Method for collecting the count of the files in the target directory.
public int Count()
{
    int files=0;
    files = dir.getNameCount();
    return files;
}
}
Run Code Online (Sandbox Code Playgroud)

java filenames path

1
推荐指数
1
解决办法
2789
查看次数

Java正则表达式删除特定的标点符号

我正在使用java格式化大量的纯文本文件,我需要删除除撇号之外的所有标点符号.当我最初为replaceAll声明设置正则表达式时,它努力摆脱我所知道的一切,除了现在我发现一个特定的文件/标点符号设置它不能正常工作.

    holdMe = holdMe.replaceAll("[,_\"-.!?:;)(}{]", " ");
Run Code Online (Sandbox Code Playgroud)

我知道我正在发表这个声明,因为所有其他标点符号都清除了,没有句号,逗号等等.我已经尝试转义()和{}字符,但它仍然没有被替换为这些字符.我一直在尝试使用Oracle文档教自己正则表达式,但我似乎无法理解为什么这不起作用.

java regex formatting replaceall

1
推荐指数
1
解决办法
3300
查看次数

如果/ else如果没有执行,即使它出现在while循环内的条件

几乎就是标题所说的.我是这个彩票号码分配的最后一点,我不知道为什么我调试时第二组if/else if语句没有显示.我知道if/else语句是互斥的 - 但是如果两个测试都不应该是if和then 这是代码.

count=0;
while(count<5)
{
    if(lottery[count] == user[count])
    {
        lotto = lottery[count];
        cout<<"So, you matched numbers with "<<lotto <<".\n";
        tally++;
    }
        if(tally==5 && count == 5)
        {
            cout<<"Congratulations, you're the grand prize winner!";
        }
        else if(tally < 5 && count == 5)
        {
            cout<<"A total of "<<tally<<" of your lottery picks matched.";
        }
        else if(tally == 0 && count == 5)
        {
            cout<<"Caution. The following comment is an inside joke. Read at your own risk.";
            cout<<"Bet you …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement while-loop

0
推荐指数
2
解决办法
554
查看次数

IntelliSense:"void"类型的值不能分配给"double"类型的实体

所以,我已删除并重新输入错误引用的行,关闭并重新打开visual studio,并查看此处发布的几个错误,显示与我的相同/相似的措辞.

我觉得这是视觉工作室的一个错误,因为即使在我删除了所有代码,保存和重新编译的内容之后,它也会在同一行上出现错误,不再存在.

"IntelliSense:类型为"void"的值无法分配给"double"类型的实体

为了防止它与工作室的错误,我想我会问我的代码中可能导致此错误的任何想法?代码中间的blockquote是它引用该错误的行.

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main ()
{
   //Declarations of vectors and basic holders for input transfer
   vector<string> candidateName;
   string inputString;
   vector<int> candidateVotes;
   int counter,inputInt,totaledVotes;
   double percentage;
   vector<double> candidatePercentage;
   //Method declaration for calculations
   void calculatePercentage (int, int, int);

   //User input to gather number of candidates, names, and votes received.
   cout <<"How many candidates need to be input?";
   cin>>counter;
   for(int i = 0;i<counter;i++)
   {
      cout<<"Please enter the candidate's last name.";
      cin>>inputString; …
Run Code Online (Sandbox Code Playgroud)

c++ methods intellisense vector

0
推荐指数
1
解决办法
5519
查看次数