Email Pattern check in Android

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by arifhasnat on 12/20/15.
*/
public class Utility {

private static Pattern pattern;
private static Matcher matcher;
//Email Pattern
private static final String EMAIL_PATTERN = “[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+”;

/**
* Validate Email with regular expression
*
* @param email
* @return true for Valid Email and false for Invalid Email
*/
public static boolean validate(String email) {
pattern = Pattern.compile(EMAIL_PATTERN);
matcher = pattern.matcher(email);
return matcher.matches();
}
}

Advertisements

Find the Largest Number

(Find the Largest Number) The process of finding the largest value is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest.
Write a program that inputs a series of 10 integers and determines and prints the largest integer. Your program should use at least the following three variables:
a) counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed).
b) number: The integer most recently input by the user.
c) largest: The largest number found so far.

Solution:

import java.util.Scanner;
class arif1{
int n;
float a,b;
public void largest(){
Scanner input =new Scanner (System.in);
System.out.println("How many number you want to enter: ");
float b[]=new float[50];
n=input.nextInt();
System.out.println("Numbers are :");
for(int i=0;i<n;i++){
b[i]=input.nextFloat();

}
for(int i=0;i<n-1;i++)

{

for(int j=0;jb[j+1])

{

float temp;

temp= b[j];

b[j]=b[j+1];

b[j+1]=temp;

}

}

}

System.out.print("largest value is :");

System.out.print(" "+b[n-1]);

}

}

public class no07 {
public static void main(String arg[]){
arif1 a=new arif1();
a.largest();

}
}

String compare

(Comparing Strings) Write a program that uses String method compareTo to compare two strings input by the user. Output whether the first string is less than, equal to or greater than the second

Solution:

import java.io.DataInputStream;
import java.io.IOException;
public class no16 {
public static void main(String arg[]) throws IOException{
DataInputStream indata=new DataInputStream(System.in);
String String1,String2;
System.out.println("Enter first String");
String1=indata.readLine();
System.out.println("First String is" +String1);
System.out.println("Enter second String");
String2=indata.readLine();
System.out.println("Second String is "+String2);
int i=String1.compareTo(String2);
if(i==0){
System.out.println(String1+" "+String2+" are equal");

}
else if(i>0){
System.out.println(String1+” is “+” greater than “+String2);

}
else if(i<0){
System.out.println(String1+” is less than “+String2);

}

}
}