Two small Java programs for practicing Java basic syntax

Source: Internet
Author: User

1, enter two number, to seek its subtraction. Present in the form of a window

1 ImportJavax.swing.JOptionPane;2 3  Public classJJCC {4      Public Static voidMain (string[] args)5     {6 String Firstnumber,secondnumber;7         intNumber1,number2;8         intHe,cha,ji,shang;9Firstnumber =Joptionpane.showinputdialogTen("Input the first integer please"); OneSecondnumber =Joptionpane.showinputdialog A("InOut The second integer please"); -Number1 =Integer.parseint (firstnumber); -Number2 =Integer.parseint (secondnumber); thehe = Number1 +number2; -Cha = number1-number2; -Ji = number1 *number2; -Shang = number1/number2; +Joptionpane.showmessagedialog (NULL, "Number1 + number2 is" -+he+ "\nnumber1-number2 is" +cha+ "\nnumber1 *" ++ "Number2 is" +ji+ "\nnumber1/number2 is" +Shang A, "Results", joptionpane.plain_message); at     } -}


2. Generate a 6-bit random string verification code (in the form of a window) (the number of bits can be changed)

1 ImportJavax.swing.JOptionPane;2 3  Public classRandomstr {4 //Public void Createrandomstr (int weishu)5 //    {6 //String str = "";7 //for (int i=1;i<=weishu;i++)8 //        {9 //            //generates a random number that represents the ASCII of the A~zTen //int intvalue = (int) (Math.random () *26+97); One //            //Converts this random number to its corresponding letter and connects to the back of STR A //str = str + (char) intvalue; - //        } - //    } the  -      Public Static voidMain (string[] args) { -     //generates a 6-bit random string of lowercase letters -         intWeishu=6; +String str = ""; -          for(inti=1;i<=weishu;i++) +         { A             //generates a random number that represents the ASCII of the A~z at             intIntvalue = (int) (Math.random () *26+97); -             //Converts this random number to its corresponding letter and connects to the back of STR -str = str + (Char) Intvalue; -         } -     //random string Generation complete - String inputstr; inInputstr = Joptionpane.showinputdialog ("Please enter the following verification code \ n" +str); -         if(Inputstr.equals (str)) to         { +Joptionpane.showmessagedialog (NULL, "Validation succeeded"); -         } the         Else *         { $Joptionpane.showmessagedialog (NULL, "Sorry, validation failed");Panax Notoginseng         } -     } the  +}

Two small Java programs for practicing Java basic syntax

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.