小编mia*_*ech的帖子

如何仅为字母测试字符串

我怎么能只对字母az这样的有效字符测试一个字符串?...

string name;

cout << "Enter your name"
cin >> name;

string letters = "qwertyuiopasdfghjklzxcvbnm";

string::iterator it;

for(it = name.begin(); it = name.end(); it++)
{
  size_t found = letters.find(it);
}
Run Code Online (Sandbox Code Playgroud)

c++

16
推荐指数
3
解决办法
7万
查看次数

从stdin获取输入

我希望从for中获取stdin的输入

3
10 20 30
Run Code Online (Sandbox Code Playgroud)

第一个数字是第二行中的数字量.这就是我得到的东西,但它停留在while循环中...所以我相信.我在调试模式下运行,数组没有分配任何值...

import java.util.*;

public class Tester {   

   public static void main (String[] args)
   {

       int testNum;
       int[] testCases;

       Scanner in = new Scanner(System.in);

       System.out.println("Enter test number");
       testNum = in.nextInt();

       testCases = new int[testNum];

       int i = 0;

       while(in.hasNextInt()) {
           testCases[i] = in.nextInt();
           i++;
       }

       for(Integer t : testCases) {
           if(t != null)
               System.out.println(t.toString());               
       }

   } 

} 
Run Code Online (Sandbox Code Playgroud)

java io stdin

14
推荐指数
1
解决办法
9万
查看次数

为什么我在运行我的 Android 项目时得到重复的类

我正在向我的应用程序添加导航抽屉。我收到错误。应用程序 gradle 同步得很好。但是当我运行应用程序时,我收到了一堆重复的类错误。我认为这可能是因为我添加了相互冲突的依赖项,并且我使用的是 v7 28.0.0 并且一些错误提到了 app: v4。我在网上看到的所有示例都使用 v7 28.0.0,尽管我在使用 v4 的 main_activity.xml 中有这个。不知道是否与错误有关。android.support.v4.widget.DrawerLayout

Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0) …
Run Code Online (Sandbox Code Playgroud)

android android-gradle-plugin

14
推荐指数
3
解决办法
3万
查看次数

我怎么能初始化通用数组

我已经给了一个骨架类"OrderSet",它实现了一个类"Set",其中一个变量T []项是通用的,我想把它初始化为一个包含5个元素的数组,但在做了一些阅读之后,我得知您无法初始化通用数组,如果是这样的话我怎么能初始化数组呢?

这是班级

public class OrderSet<T extends Comparable> implements Set<T> {

    private T[] items;
    private int theSize;

    public OrderSet()
    {
        items = (T[]) new Set[5];
    }

    @Override
    public void add(T s)
    {

    }

    @Override
    public void show()
    {

    }

}
Run Code Online (Sandbox Code Playgroud)

java arrays generics

5
推荐指数
1
解决办法
3万
查看次数

项目Euler#3永远用Java

Project Euler上的问题#3是:

13195的主要因素是5,7,13和29.

600851475143的最大主要因素是什么?

我的解决方案永远.我认为我得到了正确的实施; 但是,当用大数字进行测试时,我无法看到结果.它永远运行.我想知道我的算法是否有问题:

public class LargestPrimeFactor3 {

    public static void main(String[] args) {
        long start, end, totalTime;
        long num = 600851475143L;
        long pFactor = 0;

        start = System.currentTimeMillis();

        for(int i = 2; i < num; i++) {
            if(isPrime(i)) {                
                if(num % i == 0) {
                    pFactor = i;                        
                }
            }
        }

        end = System.currentTimeMillis();
        totalTime = end - start;
        System.out.println(pFactor + " Time: "+totalTime);
    }

    static boolean isPrime(long n) {

        for(int i = 2; i < n; …
Run Code Online (Sandbox Code Playgroud)

java primes prime-factoring

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

netbeans无法识别ArrayUtil

我正在使用以下声明

int[] numList = ArrayUtil.randomIntArray(100, 100);
Run Code Online (Sandbox Code Playgroud)

我已经进口了

import java.util.*;
Run Code Online (Sandbox Code Playgroud)

所以在这里输入正确的课程是不可能的.我正在尝试创建一个包含100个数字的数组并使用1-100中的随机数填充数组,但是netbeans在"ArrayUtil"下面放了一条红线我用鼠标扫视它以读取错误"找不到符号,Symbol:变量ArrayUtil"当我导入所有需要的类时,为什么会发生这种情况

谢谢

java netbeans

3
推荐指数
2
解决办法
2万
查看次数

为什么我无法将我的包发布到npmjs

我已经使用npmjs.com创建了一个帐户,我也正在从命令行(linux)中学习如何操作npm教程.我正处于发布测试模块的阶段.但我一直在收到错误:

You must sign up for private packages : @zentech/node
Run Code Online (Sandbox Code Playgroud)

这些都是npm发布时的错误

npm ERR! publish Failed PUT 402
npm ERR! Linux 4.10.0-33-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "publish"
npm ERR! node v4.7.2
npm ERR! npm  v3.5.2
npm ERR! code E402

npm ERR! You must sign up for private packages : @zentech/node
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

publish node.js npm

3
推荐指数
2
解决办法
1454
查看次数

BottomNavigationView 中的所选项目与背景颜色相同

我正在实现底部导航菜单。但未选择菜单中的第一项。我注意到,当我更改栏背景的颜色时,它会显示出来,原因是第一个项目“启用”颜色与导航栏的背景颜色相同。如何更改已启用选项卡以及其余项目的颜色。默认情况下它们是黑色的......假设我想将它们更改为白色。感谢主要活动的图片。http://pctechtips.org/apps/activity.png 菜单 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="@string/title_home" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="@string/title_dashboard" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_notifications" />
</menu>
Run Code Online (Sandbox Code Playgroud)

活动主文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <org.techgeorge.textrecon.PaintView
        android:id="@+id/paintView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:menu="@menu/bottom_nav_menu" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android bottomnavigationview android-bottomnav material-components material-components-android

3
推荐指数
2
解决办法
6876
查看次数

任何人都可以建议我在C++中分割名称的简单方法

我一直试图将名字分为名字和姓氏,但我确信我的实施并不是最简单的.

string name = "John Smith";
    string first;
    string last (name, name.find(" "));//getting lastname
    for(int i=0; i<name.find(" "); i++)
    {
        first += name[i];//getting firstname
    }
    cout << "First: "<< first << " Last: " << last << endl;
Run Code Online (Sandbox Code Playgroud)

提前致谢

c++

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

在其他函数python中传递函数作为参数

我有这些函数,并且我遇到错误,使用do_twice函数,但是我在调​​试它时遇到了问题

#!/usr/bin/python
#functins exercise 3.4

def do_twice(f):
    f()
    f()

def do_four(f):
    do_twice(f)
    do_twice(f)

def print_twice(str):
    print str + 'one' 
    print str + 'two'


str = 'spam'
do_four(print_twice(str))
Run Code Online (Sandbox Code Playgroud)

调试器错误

:!python 'workspace/python/functions3.4.py'
spamone
spamtwo
Traceback (most recent call last):
  File "workspace/python/functions3.4.py", line 18, in <module>
    do_four(print_twice(str))
  File "workspace/python/functions3.4.py", line 9, in do_four
    do_twice(f)
  File "workspace/python/functions3.4.py", line 5, in do_twice
    f()
TypeError: 'NoneType' object is not callable

shell returned 1
Run Code Online (Sandbox Code Playgroud)

python function

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