JAVA题

JAVA题

大题总结:

案例一:判断月份天数


    <label for="">请输入年份:</label>
                  <input type="text" id="year">
                  <label for="">请输入月份:</label>
                  <input type="text" id="month">
                  <input type="button" id="btn" value="开始计算" onclick="tian()" >

        <script>
                  function tian(){
                            let y=document.querySelector("#year").value;
                            let m=document.querySelector("#month").value;
                            switch(m){
                                 case '1':  alert(1+"月有"+31+"天");break;
                                 case '2':if((y%4==0&&y%100!=0)||y%400==0){
                                            alert(2+"月有"+29+"天");
                                              }else{
                                                     alert(2+"月有"+28+"天");
                                              }
                                              bryeak;
                                 case '3':alert(3+"月有"+31+"天");break;
                                 case '4':alert(4+"月有"+30+"天");break;
                                 case '5':alert(5+"月有"+31+"天");break;
                                 case '6':alert(6+"月有"+30+"天");break;
                                 case '7':alert(7+"月有"+31+"天");break;
                                 case '8':alert(8+"月有"+31+"天");break;
                                 case '9':alert(9+"月有"+30+"天");break;
                                 case '10':alert(10+"月有"+31+"天");break;
                                 case '11':alert(11+"月有"+30+"天");break;
                                 case  '12':alert(12+"月有"+31+"天");break;
                                 default :alert("请输入1到12的月份");break;
                  }
                  }
                  

                  
        </script>

案例二:闰年的判断

     <script>
                                    var year=1949;
                                    while(year<=2019&&year>=1949){
                                            if((year%4==0&&year%100!=0)||year%400==0){
                                                document.write(year+"  ");
                                            }
                                            year++;
                                    }
                  </script>

案例三:字符串分隔到数组里

                  <script>
                  var person=new String("吉林省.长春省.高新区.修正路");
                  var arr=["","","",""];
                  let num=0;
                  for(let i=0;i<person.length;i++){
                         if(person.charAt(i)=="."){
                                    num++;
                         }else{
                              arr[num]+=person.charAt(i);
                         }
                        
                  }
                  for(let i=0;i<arr.length;i++){
                          document.write(arr[i]+"  ");
                  }

                 </script> 

 

posted @ 2022-07-17 20:09  一只神秘的猫  阅读(41)  评论(0)    收藏  举报