Time spent here:

Thursday, 28 January 2016

java code to send attachment in email

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendFileEmail
{
   public static void main(String [] args)
   {
      
      // Recipient's email ID needs to be mentioned.
      String to = "abcd@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "web@gmail.com";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Create the message part 
         BodyPart messageBodyPart = new MimeBodyPart();

         // Fill the message
         messageBodyPart.setText("This is message body");
         
         // Create a multipar message
         Multipart multipart = new MimeMultipart();

         // Set text message part
         multipart.addBodyPart(messageBodyPart);

         // Part two is attachment
         messageBodyPart = new MimeBodyPart();
         String filename = "file.txt";
         DataSource source = new FileDataSource(filename);
         messageBodyPart.setDataHandler(new DataHandler(source));
         messageBodyPart.setFileName(filename);
         multipart.addBodyPart(messageBodyPart);

         // Send the complete message parts
         message.setContent(multipart );

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

Wednesday, 27 January 2016

my first android children game:

APP NAME :  DOT FUN
AUTHOR    :  K.NAVEENRAJ
TOOL          :  MIT APP INVENTOR 2
VERSION   :  1.0


Tuesday, 26 January 2016

how to find a number is divisible by 5:

 You’ll be happy to know that checking for divisibility by 5 is really easy. The quick and dirty tip is that for a number to be divisible by 5, it must end with either a 0 or a 5. For example, the numbers 5, 10, 15, 20, and so on up to 1,005, 1,010, and on and on forever, are all divisible by 5 since they all end in either a 0 or 5. On the other hand, the numbers 7 and 3,111,428 are not divisible by 5 since they do not end in either a 0 or 5.

Why does this work? Well, the reason is as easy as the tip: It’s simply that no matter what you multiply the number 5 by, the result is always a number that ends in 0 or 5. That’s all there is to it!
 
- See more at: http://www.quickanddirtytips.com/education/math/how-to-tell-if-a-number-is-divisible-by-4-5-or-6#sthash.nhvism2E.

Monday, 4 January 2016

Db & His Crush:

Problem Statement
Db proposed his Crush on phone call . His crush has a lot of attitude as she is very beautiful .She gives him a question and says that I will accept your proposal if you will give correct answer of my question. As Db loves his crush a lot so he is asking for help .Now your task is to help Db. The question asked by his crush is: Given an array of n elements .You have to count the minimum number of replacement to make all numbers in array similar. The range of every element of array is from 1 to 3 inclusive.
Input Format
The first line contains an integer n (1 ≤ n ≤ 10^6).
The second line contains n elements.
Output Format
Print the minimum number of replacement to make all numbers in array similar.
Sample Input
9
1 3 2 2 2 1 1 2 3
Sample Output
5
Explanation
We can replace all 1 and 3 with 2 so the total count is 5.

SOLUTION in PYTHON:

n = input()
d = {1:0, 2:0, 3:0}
a = map(int, raw_input().split())
for ii in a: d[ii]+=1
print min(d[1]+d[2], min(d[1]+d[3], d[2] + d[3]))

SOLUTION IN C++:

cin >> n;
for (int i=0;i<n;i++){
    cin >> x;
    a[x]++;
}
int ans=a[2]+a[3];
ans=min(ans,a[1]+a[3]);
ans=min(ans,a[1]+a[2]);
cout << ans;
 }