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