#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
cout<<"enter ur no. plz";
cin>>i;
cout<<"ur no. is:"<<i;
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此代码未显示我输入的整数.它在输入一个整数并返回后返回.我正在使用开发C++.
我有几个关于C语法的问题.
ch = (char *) malloc( sizeof( char ) * strlen(src) );
第一个括号是什么意思(char*)?
c=getch();
switch(c) {
case '1' :{
我的老师问为什么'这种类型'的引号被使用而不是"双重".我说如果使用char变量,它是C语法.但他说不!为什么使用单引号而不是双引号?
有时,当scanf
没有任何事情发生时,它已被使用两次来扫描一些东西.这个问题的原因是什么?例如:
printf("enter string \n");
scanf("%s",&str);
printf("enter char \n");
scanf("%c",&ch); //does not scan my char
scanf("%c",&ch); //with this second line do scan my char
Run Code Online (Sandbox Code Playgroud)我有下面的代码.我想将此列表中的所有项目转换为大写.
在Linq有办法做到这一点吗?
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
public class MyClass
{
List<Person> myList = new List<Person>{
new Person { FirstName = "Aaa", LastName = "BBB", Age = 2 },
new Person{ FirstName = "Deé", LastName = "ève", Age = 3 }
};
}
Run Code Online (Sandbox Code Playgroud)
更新
我不想循环或逐字段去.有没有办法通过反射来大写每个属性的值?
我有一个迭代a的函数,const char *
并使用该字符将对象添加到一个实例中,std::map
如果它是一系列已识别的字符之一.
#define CHARSEQ const char*
void compile(CHARSEQ s) throw (BFCompilationError)
{
std::cout << "@Receive call " << s << std::endl;
for(int i = 0; s[i] != '\0'; i++)
{
if (std::string("<>-+.,[]").find_first_of(s[i]) == std::string::npos)
{
throw BFCompilationError("Unknown operator",*s,i);
}
std::cout << "@Compiling: " << s[i] << std::endl;
std::cout << "@address s " << (void*)s << std::endl;
std::cout << "@var s " << s << std::endl;
controlstack.top().push_back(opmap[s[i]]);
}
}
Run Code Online (Sandbox Code Playgroud)
传递的字符序列是"++++++++++."
前三次迭代,print语句显示'+','+'和'+'的预期值,值s
继续为"+++++++++++++++++++++++++++++++++++++++++++++++++++ +." 然而,在第四次迭代, …
我正在尝试编写一个primeify
接受符号的函数,并返回附加了"-prime"的符号.我想要的输出是:
[1] > (primeify 'y)
Y-PRIME
Run Code Online (Sandbox Code Playgroud)
(或者y-prime
,这种情况不是主要观点,尽管后来可能会变得相关).
这是我当前(错误的)实现:
(defun primeify (sym)
(make-symbol (concatenate 'string (string sym) "-prime")))
Run Code Online (Sandbox Code Playgroud)
但是,make-symbol
通过使用其他格式将其混乱来修改输出.我的输出是:
[1]> (primeify 'y)
#:|Y-prime|
Run Code Online (Sandbox Code Playgroud)
有没有办法避免这个额外的处理make-symbol
,或者我可以用来实现这个的另一个功能?这甚至可以在lisp中实现吗?
如何删除common-lisp中列表中的重复列表?我试过这个:
(remove-duplicates '( (1 2 3) (1 2 3)))
Run Code Online (Sandbox Code Playgroud)
但它评估的 ((1 2 3) (1 2 3))
不是((1 2 3))
.
谢谢.
假设我有一个方法foo
:
public Integer foo () { return 1; }
Run Code Online (Sandbox Code Playgroud)
以上哪个选项的价格较低?拳击还是拆箱?
assert(1, (int) foo()));
Run Code Online (Sandbox Code Playgroud)
与
assert((Integer)3, foo());
Run Code Online (Sandbox Code Playgroud) 好的,我正在审查Java考试,其中一个问题是:我们希望开发一个程序来计算集合中偶数和奇数的数量("偶数"意味着可以被2整除,"奇数"意思是不能被2)整除.我们将使用零作为集合已完全输入的指示符,并且不应将此零作为集合的一部分计算.询问用户一个整数序列,以零结尾.输出偶数整数和奇数整数.
当我运行我的代码时,由于某种原因,第一个变量总是被计为偶数,无论整数是多少.我不能为我的生活找出原因.示例:我输入23,22,25.它表示2甚至1个奇数.但是,如果我输入22,23,25,则表示1甚至2个奇数.
这是我的代码:
public class Problem4_Exam1Practice {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Enter Numbers");
int x = IO.readInt();
int even = 0;
int odd = 0;
while(x != 0) {
x = IO.readInt();
if (x % 2 == 0) {
even = even + 1 ;
}else{
odd = odd + 1 ;
}
}
System.out.println(even + " even " + odd + " odd ");
}
}
Run Code Online (Sandbox Code Playgroud) 当我编写android时,我遇到了以下事情
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = _inflater.inflate(R.layout.abstract_list_row_item, null);
move.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// if btn is clcked then data is changed an we need to refresh framents
MainAppDataController.getInstance().setIsDataChanged(true);
callWhiteListDB = new CallWhiteListDB(_context);
callWhiteListDB.openToWrite();
callWhiteListDB.insert(allContacts.get(position).name, allContacts.get(position).number);
callWhiteListDB.close();
callBlackListDB = new CallBlackListDB(_context);
callBlackListDB.openToWrite();
callBlackListDB.deleteSingleItem(allContacts.get(position).dbId);
callBlackListDB.close();
populateList(position);
notifyListView(view);
}
});
return convertView;
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,getView()
方法有像int position,View convertView,ViewGroup parent这样的参数.我的观察是在我开始使用位置变量时onclick()
,Eclipse抛出编译错误并要求将位置作为final.我为什么要把它作为最终版?AFAIK final用于常量.
Iterator<String> ir = arr.iterator();
while(ir.hasNext()) {
String an = ir.next();
System.out.println(an);
}
Run Code Online (Sandbox Code Playgroud)
在ArrayList
ir中返回指向第一个的列表对象.现在ir.next()
必须指向下一个对象.那么为什么它在循环中第一次运行时指向第一个对象?
另外,
ListIterator<String> ir= arr.listIterator();
while(ir.hasNext())
{
String an= ir.next();
ir.set(an + '+');
System.out.println(an);
}
Run Code Online (Sandbox Code Playgroud)
为什么它不附加'+'
?它只打印原件ArrayList
.