我试图创建我的第一个iphone程序,我意识到制作2个dims的数组或矩阵对我来说很难...... :-(
*我如何以及在哪里声明这样的东西(取自java)所以所有的功能都可以看到它:
int[] myArray = new int[6];
Run Code Online (Sandbox Code Playgroud)
*我怎样才能转发此功能:
public int[] sortArray (int[] myArray){
int tmp;
for (int x = 0; x < myArray.length; x++) {
for (int y = x+1; y < 6; y++) {
if (myArray[y] < myArray[x]) {
tmp = myArray[x];
myArray[x] = myArray[y];
myArray[y] = tmp;
}
}
}
return myArray;
}
Run Code Online (Sandbox Code Playgroud)
*以及我如何称呼此功能?
sortArray(myArray);
Run Code Online (Sandbox Code Playgroud)
谢谢大家!沙龙
我是初学者。我对它们之间的区别感到困惑。我读过一些答案,并意识到区别之一是动态数组可以被删除,而普通数组则不能。但还有其他差异吗?比如它们的功能、尺寸等等?
好吧,我读过这样一个例子,如果我用普通数组 {int p [i];} 替换动态数组 {p= new (nothro) int[i];} ,我没有看到任何区别。
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int i,n;
int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
cout << "You have entered: ";
for …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用NSInteger计算开启和关闭的IOS项目.在2200读取的时间相当于晚上10点.我想知道是否有一些东西在关闭后的一个小时内,所以我将整数(工作)中的实际世界时间与结束时间进行比较 - 100但数学运算没有按预期工作.
自定义类:
@property (assign) NSInteger *sus;
@property (assign) NSInteger *sue;
Run Code Online (Sandbox Code Playgroud)
在控制器中:
custom_class *location = object
resultINT = real world time in Integer with 24 hr
NSLog(@"Result INT: %i", resultInt);
NSLog(@"location.sue: %i", location.sue);
NSLog(@"Location - 1hr %i", location.sue -100);
NSInteger *yellowEnd = location.sue - 100;
NSLog(@"Yellow %i", yellowEnd);
Run Code Online (Sandbox Code Playgroud)
结果:
2014-07-13 18:23:51.269 Time-Genesis-Marcus[7591:416078] Result INT: 1823
2014-07-13 18:23:51.269 Time-Genesis-Marcus[7591:416078] location.sue: 2200
2014-07-13 18:23:51.269 Time-Genesis-Marcus[7591:416078] Location - 1hr 1800
2014-07-13 18:23:51.270 Time-Genesis-Marcus[7591:416078] Yellow 1800
Run Code Online (Sandbox Code Playgroud)
为什么第三和第四行没有返回2100?谢谢
我正在自学C语言.我有以下代码,通过char向前和向后打印字符串char:
#include<stdio.h>
#include<string.h>
main(){
char *str;
fgets(str, 100, stdin);
//printf("%i", strlen(str));
int i;
for(i = 0; i < strlen(str) - 1; i++){
printf("%c", str[i]);
}
for(i = strlen(str); i > -1; i--){
printf("%c", str[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
运行时,它给我以下输出(假设我输入"hello"):
cello
ollec
Run Code Online (Sandbox Code Playgroud)
另外,如果我取消注释第7行代码,我得到以下输出(假设我输入"hello"):
6 ?
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我无法弄清楚我正在做什么导致输出中的第一个字符发生变化.在第二个例子中,我知道字符串长度为6,因为'h'+'e'+'l'+'l'+'o'+'\ 0'= 6.这很好,但是在哪里锹符号来自?为什么只打印其中一个?
对我来说很明显,我对这里发生的事情有一些基本的误解,我无法在其他地方找到任何这方面的例子.任何人都可以解释这里出了什么问题吗?
class Test
{
private:
int x;
int y;
public:
Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
Test &setX(int a) { x = a; return *this; }
Test &setY(int b) { y = b; return *this; }
void print() { cout << "x = " << x << " y = " << y << endl; }
};
int main()
{
Test obj1(5, 5);
obj1.setX(10).setY(20);
obj1.print();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码输出为10 20 …
我在Obj-C上使用这个代码,它确实有效:
CALayer *btnLayer = [self.priceLabel layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:5.0f];
Run Code Online (Sandbox Code Playgroud)
它确实在我的按钮CALayer上形成了圆角.
但是没有在swift上工作:
var btnLayer:CALayer! = self.priceLabel.layer
[btnLayer.masksToBounds:true]
[btnLayer.cornerRadius = 5.0]
Run Code Online (Sandbox Code Playgroud)