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;

}

Wednesday, 23 March 2016

Use of NSNumber in iOS (Objective C)

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSNumber *aBool=[NSNumber numberWithBool:NO];
        NSNumber *aChar=[NSNumber numberWithChar:'z'];
        NSNumber *anInt=[NSNumber numberWithInt:234545];
        NSNumber *aDouble=[NSNumber numberWithDouble:34.345];
        
        NSLog(@ "%@",[aBool boolValue]?@ "YES":@ "NO");
        NSLog(@ "%c",[aChar charValue]);
        NSLog(@ "%lu",[anInt integerValue]);
        NSLog(@ "%f",[aDouble doubleValue]);
        
        //Assigning direct literals is valid.
        aBool=@ YES;
        NSLog(@ "%@",[aBool boolValue]?@ "YES":@ "NO");
        
        //NSNumber could be used directly with any data type.
        float x=5;
        NSNumber *result=@(x*10);
        NSLog(@ "%@",result);
        
        //could also be used in counter to store value at runtime.
        NSNumber *counter=@ 0;
        for (int i=0; i<10; i++) {
            counter=@ ([counter integerValue]+1);
        }
        NSLog(@ "%@",counter);
        
        //Use of NSNumber with NSComparisonResult
        NSNumber *anInteger=@ 65;
        NSNumber *anotherInt=@ 42;
        NSComparisonResult result1 = [anInteger compare:anotherInt];
        if (result1 == NSOrderedAscending) { //It will return 1 if true.
            NSLog(@ "65<42");
        }
        else if (result1 == NSOrderedSame){ //It will return 0 if true.
            NSLog(@ "65==42");
        }
        else if (result1 == NSOrderedDescending){ //It will return -1 if true.
            NSLog(@ "65>42");
        }
    }
    return 0;

}

Monday, 21 March 2016

String properties in iOS (Objective C)


  • Length
  • UTF8String
  • Capitalised a String
  • Uppercase 
  • Lowercase
  • Double Value
  • Float Value
  • Integer Value
  • Bool Value

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSString *str=[[NSString alloc]init];
        str=@ "Akshay sarda";
        NSLog(@ "%@",str);
        
        char *arr="Akshay";
        NSString *temp=[[NSString alloc]initWithCString:arr encoding:NSUTF8StringEncoding];
        NSString *a=[[NSString alloc]initWithUTF8String:arr];
        NSLog(@ "%@ %@",a,temp);
        
        int count;
        NSString *arr1=[[NSString alloc]initWithFormat:@ "Count is %d",count];
        NSLog(@ "%@",arr1);
        
        //String Length
        NSLog(@ "Length is %lu",str.length);
        NSLog(@ "Length is %lu",a.length);
        
        //UTF8String
        NSLog(@ "String is %s",temp.UTF8String);
        
        //Capitalized a String
        NSLog(@ "%@",str.capitalizedString); //It will Capitalized the First letter of each word.
        
        //Lower case String
        NSLog(@ "%@",a.lowercaseString);
        
        //Upper case String
        NSLog(@ "%@",str.uppercaseString); //It will convert the complete string in Capital Letter.
        
        //Double Value
        NSString *pi=@ "3.14";
        NSLog(@ "%f",pi.doubleValue);
        
        //Float Value
        NSLog(@ "%f",pi.floatValue);
        
        //Integer Value
        NSLog(@ "%lu",pi.integerValue);
        
        //BOOL Value
        BOOL k=YES;
        NSLog(@ "%d",k);
    }
    return 0;
}

Sunday, 20 March 2016

String Methods in iOS

  • Appending a String
  • String Padding
  • Range of String 
  • Substring with Range
  • Components Separated by String
  • Components Separated by Character in set
  • Components joined by String
  • String separated by comma (,)  added in array
  • Substring from String
  • Substring to Index
  • String by replacing occurrences of String
  • Case sensitive Comparison

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        //Appending a String
        NSString *errortag=@ "Error: ";
        NSString *errorstring=@ "premature end of file";
        NSString *errormessage=[errortag stringByAppendingString:errorstring];
        NSLog(@ "%@",errormessage);
        
        //String Padding
        NSString *temp=@ "Akshay";
        temp= [temp stringByPaddingToLength:8 withString:@ "." startingAtIndex:0];
        NSLog(@ "%@",temp);
        //Error on setting the index to 1 when there is no space in the withString.
        
        temp=@ "Akshay";
        temp=[temp stringByPaddingToLength:10 withString:@ ". " startingAtIndex:1];
        NSLog(@ "%@",temp);
        
        //rangeOfString
        NSString *new=@ "Stefan";
        NSRange range=[new rangeOfString:@ "John"];
        NSLog(@ "Location : %lu Length: %lu",range.location,range.length);
        //Range starting from 0, doesn't make sense.
        
        //substringWithRange
        NSString *str=@ "DamonSalvetore";
        NSRange range1={0,6};
        NSString *str1=[str substringWithRange:range1];
        NSLog(@ "Substring with Range is %@",str1);
        NSString *str2=[str substringWithRange:NSMakeRange(5, 6)];
        NSLog(@ "Range is %@",str2.capitalizedString);
        
        //Components Seperate by String
        NSString *list=@ "Damon, Alina, Kathrine";
        NSArray *listitem= [list componentsSeparatedByString:@ ","];
        for (int i=0; i<listitem.count; i++) {
            NSLog(@ "%@",[listitem objectAtIndex:i]);
        }
        
        //Components seperated by character in set
        NSString *st=@ "A~B~C~D~E";
        NSArray *starr=[st componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@ "~"]];
        NSLog(@ "%@",starr);
        NSString *st1=@ "A~B^C~D^E";
        NSArray *starr1=[st1 componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@ "^~"]];
        NSLog(@ "%@",starr1);
        
        //Components Joined by String
        NSArray *pathArray=[NSArray arrayWithObjects:@ "here",@ "dragons", @ "are", @ "stupid", nil];
        NSLog(@ "%@",[pathArray componentsJoinedByString:@ " "]);
        
        //String seperated by comma(,) added in array, and showed as desired output.
        NSString *gon=@ "Dragons,are,smart";
        NSArray *path=[gon componentsSeparatedByString:@ ","];
        NSLog(@ "%@",[path componentsJoinedByString:@ " "]);
        
        //substring from Index
        NSString *sub=@ "Elina";
        NSLog(@ "%@",[sub substringFromIndex:3]);
        
        //substring to Index
        NSLog(@ "%@",[sub substringToIndex:3]);
        NSString *output=[sub substringToIndex:3];
        NSLog(@ "%@",[output stringByPaddingToLength:6 withString:@ "." startingAtIndex:0]);
        
        //string by replacing occurences of string
        NSLog(@ "%@",[sub stringByReplacingOccurrencesOfString:@ "hay" withString:@ "Emi"]);
        
        //case insensitive Comparision
        NSLog(@ "Case Insensitive : %lu",[sub caseInsensitiveCompare:@ "aaksha"]);
        NSLog(@ "Case Sensitive %lu",[sub compare:@ "Akshay"]);
        
        //is equal to String (Returns BOOL i.e. 1 or 0 | YES or NO)
        NSLog(@ "Comparision returns Bool value : %d",[sub isEqualToString:@ "Akshay"]);
        
        //BOOL
        NSLog(@ "Prefix : %d",[sub hasPrefix:@ "Caroline"]);
        NSLog(@ "Suffix : %d",[sub hasSuffix:@ "caroline"]);
    }
    return 0;

}

Saturday, 19 March 2016

Amazon Prime Air

Amazon Prime Air


  • Types of Drone
  • Technical Specification
  • Control Measure and Sensors
  • Currently Flying in
  • A video showing how it works
Click here to know about Amazon Prime Air.

Program for ArrayList in C#

ArrayList

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ArrayList0
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList aList = new ArrayList();
            aList.Add(45);
            aList.Add(60);
            aList.Add(78);
            aList.Add(75);
            aList.Add(12);
            aList.Add(34);
            aList.Add(89);
            aList.Add(90);
            aList.Add(67);
            aList.Add(60);
            int n = aList.Count;
            Console.WriteLine();
            Console.WriteLine("TotaList number of element in an array {0}  ",n);
            Console.WriteLine();
       foreach (int b in aList)
            {
                Console.WriteLine(b);
               }
            aList.Sort();
            aList.Reverse();
            Console.WriteLine("Sorted in Descending order : ");
            foreach (int a in aList)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine();
            aList.RemoveAt(9);
            Console.WriteLine("Lowest marks removed : ");
            foreach (int b in aList)
            {
                Console.WriteLine(b);
            }
            Console.WriteLine();
            Console.WriteLine(aList.Contains(75));
            
            aList.Clear();
            Console.WriteLine("Removed aListl the List of Array");
            Console.ReadKey();
        }
    }
}

Friday, 18 March 2016

String Operation in C#

String Operations :
1. Get the Substring from a string
2. Reverse a string
3. Concatenate a string
4. Check whether a string contains a particular string or not
5. Compare two strings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringOperation
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("String Operations");
            Console.WriteLine();
            Console.WriteLine("1. Get the substring from a string.");
            string s1 = "Dream big and dare to fail, ";
            string s2 = "Never give up on your Dream.";          
            string get = s1.Substring(0,6);
            Console.WriteLine("String is : {0}", s1);
            Console.WriteLine("Substring of this String is : {0}",get);
            Console.WriteLine(); Console.WriteLine();
           
            Console.WriteLine("2. Reverse a String.");
            string str = "Damon Salvatore";
            Console.WriteLine("Original String is : {0}",str);
            char[] cArray = str.ToCharArray();
            string reverse = String.Empty;
            for (int i = cArray.Length - 1; i > -1; i--)
            {
                reverse += cArray[i];
            }
            Console.WriteLine("After reverse the String is : {0}",reverse);
            Console.WriteLine(); Console.WriteLine();

            Console.WriteLine("3. Concatinate a String");
            string concat = s1 + s2;
            Console.WriteLine("After Concatination the string is : ");
            Console.WriteLine(">>> {0}",concat);
            Console.WriteLine(); Console.WriteLine();

            Console.WriteLine("4. Check whether a string contain a particular string.");
            if (s1.Contains("Dream"))
                Console.WriteLine("Dream does contain in string.");
            else
                Console.WriteLine("It doesnot contain.");
            Console.WriteLine(); Console.WriteLine();

            Console.WriteLine("5. Compare two string.");
            s1 = "Ramandeep";
            s2 = "Ramandeep";
            if(s1==s2)
                Console.WriteLine("Is equal");
            else
                Console.WriteLine("Is not equal");
            Console.ReadKey();
        }
    }
}

.Net Assignment

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 ...