Monday, 28 March 2016

Circular Shift in Java

class CicularShiftn
{
public static void main(String[] args)
{
int a[]=new int[10];
int temp,n,i,j,b=2;
Console con=System.console();
System.out.println("Enter the 10 elements in array : ");
for(i=0;i<10;i++)
{
int no=(int)(Math.random()*100);
a[i]=no;
}
System.out.println("Array elements are : ");
for(int value:a)
System.out.println(value);
System.out.println("Enter the position from which you want to shift : ");
n=Integer.parseInt(con.readLine());
i=0; j=n;
while(i<j)
{
temp=a[i];
    for(i=0;i<9;i++)
    a[i]=a[i+1];
   a[i]=temp;
   i=0;
   j--;
}
System.out.println("Now array elements are ");
for(int value1:a)
System.out.println(value1);
}
}

Collection in iOS (Objective C)

Use of NSSet

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //NSSet Example which uses its own for loop to print seperating by comma.
        NSSet *names=[NSSet setWithObjects:@ "Stefan",@ "Silas",@ "Damon", nil];
        NSLog(@ "%@",names);
        
        //To calculate the number of objects in a set.
        NSLog(@ "The set has %lu elements",names.count);
        
        //Fast Enumeration
        for(id name in names){
            NSLog(@ "%@",name);
        }
        
        //enumerate objects using Block
        [names enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
            NSLog(@ "Current item: %@",obj);
            if ([obj isEqualToString:@ "Damon"]) {
                NSLog(@ "I was looking for Damon and I found him!");
                *stop=YES; //stop enumerating item
            }
        }];
    }
    return 0;

}

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...