[JAVA100 example]003, array data manipulation

Source: Internet
Author: User
Tags mail

public class myarray{


//initialization of array variables


char[] Cnum = {´1´,´2´,´3´,´4´,´5´,´6´,´7´,´8´,´9´,´0´};


char[] CStr = {´a´,´b´,´c´,´d´,´e´,´f´,´g´,´h´,


´i´,´j´,´k´,´l´,´m´,´n´,´o´,´p´,


´q´,´r´,´s´,´t´,´u´,´v´,´w´,´x´,´y´,´z´};


int[] Imonth = {31,28,31,30,31,30,31,31,30,31,30,31};


string[] Smail = {"@", "."};


/**


*<br> Method Description: Verifying email


*<br> input parameter: String Spara the verified e-mail character


*<br> return Type: Boolean returns True if the format of the checksum conforms to the e-mail format; false


*/


public boolean isMail (String Spara) {


for (int i=0;i<smail.length;i++) {


if (Spara.indexof (smail[i)) ==-1)


return false;


  }


return true;


  }


/**


*<br> Method Description: Judge whether it is a digital


*<br> input parameter: String Spara. Need to judge the string


*<br> return Type: Boolean. Returns true if both are numeric types, otherwise returns false


*/


public boolean isnumber (String Spara) {


int iplength = Spara.length ();


for (int i=0;i<iplength;i++) {


char ctemp = Spara.charat (i);


Boolean btemp = false;


for (int j=0;j<cnum.length;j++) {


if (Ctemp==cnum[j]) {


btemp = true;


break;


     }


    }


if (!btemp) return false;


   }


return true;


  }


/**


*<br> Method Explanation: Judge whether all is the English character


*<br> input parameter: String Spara. The character to check


*<br> return Type: Boolean. If all characters return true; False


*/


public boolean isstring (String Spara) {


int iplength = Spara.length ();


for (int i=0;i<iplength;i++) {


char ctemp = Spara.charat (i);


Boolean btemp = false;


for (int j=0;j<cstr.length;j++) {


if (Ctemp==cstr[j]) {


btemp = true;


break;


     }


    }


if (!btemp) return false;


   }


return true;


  }


/**


*<br> Method Description: Judge whether it is a leap year


*<br> input parameter: int Ipara. The year to Judge


*<br> return Type: Boolean. Returns true if it is a leap year, otherwise returns false


*/


public boolean chickday (int ipara) {


return ipara%100==0&&ipara%4==0;


  }


/**


*<br> Method Description: Check the date format is correct


*<br> input parameter: String Spara. The date character to check


*<br> return type: Int. 0 Days period format is correct,-January or this day is not required,-2 days date format is incorrect


*/


public int Chickdata (String Spara) {


Boolean btemp = false;


//input date length is incorrect


if (spara.length ()!=10) return-2;


//Get year


String syear = spara.substring (0,4);


//Judging whether the year is a digital


if (!isnumber (syear)) return-2;


//Get month


String smonth = spara.substring (5,7);


//Determine whether the month is a digital


if (!isnumber (smonth)) return-2;


//Get Day


String sday = spara.substring (8,10);


//Judgment Day is a digital


if (!isnumber (sday)) return-2;


//Convert year, month and day to digital


int iyear = Integer.parseint (syear);


int imon = Integer.parseint (smonth);


int iday = Integer.parseint (Sday);


if (imon>12) return-1;


//Leap Year February processing


if (Imon==2&&chickday (iyear)) {


if (iday>29) return 2;


}else{


if (iday>imonth[imon-1]) return-1;


  }


return 0;


  }


/**


*<br> Method Description: Main method, Test with


*<br> input Parameters:


*<br> return type:


*/


public static void Main (string[] arges) {


myarray MA = new MyArray ();


//Check email address


Boolean bmail = Ma.ismail ("tom@163.com");


System.out.println ("1 bmail is" +bmail);


bmail = Ma.ismail ("tom@163com");


System.out.println ("2 bmail is" +bmail);


//Demo is digital


Boolean bisnum = Ma.isnumber ("1234");


System.out.println ("1:bisnum=" +bisnum);


bisnum = Ma.isnumber ("123r4");


System.out.println ("2:bisnum=" +bisnum);


//Demo is English character


Boolean bisstr = ma.isstring ("Wer");


System.out.println ("1:bisstr=" +bisstr);


bisstr = ma.isstring ("Wer3");


System.out.println ("2:bisstr=" +bisstr);


//Demo Check date


int iistime = Ma.chickdata ("2003-12-98");


System.out.println ("1:iistime=" +iistime);


iistime = Ma.chickdata ("2003-111-08");


System.out.println ("2:iistime=" +iistime);


iistime = Ma.chickdata ("2003-10-08");


System.out.println ("3:iistime=" +iistime);


iistime = Ma.chickdata ("2000-02-30");


System.out.println ("4:iistime=" +iistime);


  }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.