Author: BIM Notes
Java 2022 Solution || BIM STUDY Notes
// Q.N0 11) TO FIND THE SECOND HIGHEST VALUE IN AN ARRAY
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package bimnotessolutions; public class Regular2022 { public static void main(String[] args) { int a[] = {1,2,3,4,5}; for(int i=0;i<a.length;i++){ for(int j = i+1;j<a.length;j++){ if(a[i]>a[j]){ int temp = a[i]; a[i] = a[j]; a[j] = temp; } } } int index = a.length-2; System.out.println("the second largest value is :"+a[index]); } } |
// Q.N0 12)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package bimnotessolutions; class Product{ private String name; private int qty,price; public Product(String name, int qty, int price) { this.name = name; this.qty = qty; this.price = price; } public String getName() { return name; } public int getQty() { return qty; } public int getPrice() { return price; } public int getTotal(){ return this.getQty()*this.getPrice(); } } public class Regular2022 { public static void main(String[] args) { Product p1 = new Product("bread",2,500); Product p2 = new Product("muffins",4,600); System.out.println("the total sum is :"+(p1.getTotal()+p2.getTotal())); } } |
// Q.N0 13) implementing thread using Runnable class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package bimnotessolutions; class ThreadExample implements Runnable{ public void run(){ try{ for(int i = 100 ; i <=200 ; i++){ Thread.sleep(1500); if(i%2==0){ System.out.print(i+" "); } } }catch(Exception err){ System.out.println(err); } } } public class Regular2022 { public static void main(String[] args) { ThreadExample te = new ThreadExample(); Thread t1 = new Thread(te); t1.start(); } } |
Q.NO 15)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
package bimnotessolutions; class MyException extends Exception{ MyException(String msg){ super(msg); } } class Person{ private String name; private int age; public void setName(String name){ this.name = name; } public void setAge(int age) throws MyException{ if(age<0 || age>100){ throw new MyException("age should be between the age"); } else{ this.age =age; } } } public class Regular2022 { public static void main(String[] args) throws MyException { Person p = new Person(); p.setName("Ram"); try{ p.setAge(150); }catch(MyException err){ System.out.println(err); } } |
Continue Reading
web 2022 Solution || BIM Study Notes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> <style> table,td,th{ border: 1px solid black ; border-collapse: collapse; } </style> </head> <body> <table> </table> <script> var students = [[1,"Arbind","bim"],[1,"bishal","bhm"],[1,"raju","csit"],[1,"ram","bbm"],[1,"sam","bbm"]] var table=`` table+=`<tr> <th>roll</th> <th>name</th> <th>faculty</th> </tr>` for(var i = 0 ; i < students.length;i++){ table+=`<tr> <td>${students[i][0]}</td> <td>${students[i][1]}</td> <td>${students[i][2]}</td> </tr>` } var data = document.querySelector("table") data.innerHTML=table </script> </body> </html> |
Q.NO 12) javaScript code to check if the given number is multiple of 5 or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <form> Enter the number : <input type="text" name="number" id="number"> <button>check</button> </form> <script> var button = document.querySelector("button") button.addEventListener('click',(e)=>{ e.preventDefault() var number = parseInt(document.getElementById('number').value) if(number%5==0)alert("It is the multiple of 5") else alert("It is not the multiple of 5") }) </script> </body> </html> |
Q.NO 14) HTML code to generate the following table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <style> table,td{ border:1px solid black; border-collapse: collapse; padding:20px; } </style> <body> <table> <tr> <td></td> <td rowspan="2"></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> </table> </body> </html> |
Q.NO 16 ) Example to show client side validation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <form> username : <input type="text" name="username" id="username"> <br> password : <input type="text" name="password" id="password"> <br> contact : <input type="text" name="contact" id="contact"> <br> <button name="submit" id="submit">submit</button> </form> <script> var button = document.querySelector("#submit") button.addEventListener('click',(e)=>{ e.preventDefault() var username= document.getElementById('username').value var password= document.getElementById('password').value var contact= document.getElementById('contact').value var usernameRegex =/^([a-zA-Z])+([0-9]?)+$/ var passwordRegex = /^[A-Za-z0-9]{6}$/ var contactRegex = /^([0-9]){10}$/ if(username.match(usernameRegex) && password.match(passwordRegex) && contact.match(contactRegex)) alert('success') else alert('fail') }) </script> </body> </html> |
Continue Reading
web 2021 Makeup solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<!DOCTYPE html> <html> <head> <title>Nested table</title> </head> <body> <table border="1"> <tr> <th>id</th> <th>name</th> <th>mark</th> </tr> <tr> <td>1</td> <td>bishal</td> <td>50</td> </tr> <tr> <td>2</td> <td>bijay</td> <td> <table border="1"> <tr> <th>theory</th> <th>practical</th> </tr> <td>40</td> <td>60</td> </table> </td> </tr> </table> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<head> <title>JavaScript</title> </head> <body> <script> function SumOfArray(array){ var sum = 0; for(var i = 0 ; i < array.length;i++ ){ if(array[i]%5==0 && array[i]%9==0){ sum+=array[i]; } } console.log("the sum is "+sum) } sumOfArray([1,2,4,5,6]); </script> </body> </html> |
Q.NO) 14 source code to display the following code using divs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<head> <title>div design</title> </head> <style> div{ text-align: center; color: white; justify-items: center; align-items: center; } .main{ width:400px; height:400px; } .div1{ width:400px; height:20px; background-color: green; } .div2{ width:400px; height:20px; background-color: rgb(24, 10, 184); } .div3{ height:340px; width:200px; float:left; background-color: yellow; } .div4{ height:340px; width:200px; float:right; background-color: rgb(25, 174, 190); } .div5{ width:400px; background-color: rgb(30, 28, 25); } </style> <body> <div class="main"> <div class="div1">This is header</div> <div class="div2">This is Nagivation bar</div> <div class="div3">left content</div> <div class="div4">right content</div> <div class="div5">this a footer</div> </div> </body> </html> |
Q.No 15) Source code to design and validate the form below. Assume all the required validation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<head> <title>Document</title> </head> <body> <form name="validate"> <table border="1"> <tr> <td>Name</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" id="email"></td> </tr> <tr> <td>Zip Code</td> <td><input type="number" name="zip" id="zip"></td> </tr> <tr> <td>Country</td> <td> <select name="country" id="country"> <option value="-1">choose yours</option> <option value="nepal">nepal</option> <option value="india">india</option> </select> </td> </tr> <tr> <td></td> <td><button name="submit" id="submit">submit</button></td> </tr> </table> </form> <script> var button = document.querySelector('#submit') button.addEventListener('click',function(e){ e.preventDefault(); var name = document.getElementById('name').value var email = document.getElementById('email').value var zip = document.getElementById('zip').value var country = document.getElementById('country').value var nameregex = /[a-zA-Z]+$/ var emailregex = /[^0-9]+@gmail\.[com]$/ var zipregex = /[0-9]{10}$/ if(name.match(nameregex) && email.match(emailregex) && zipregex.match(zipregex) &&country! =-1 ){ alert('validation sucess') } }) </script> </body> </html> |
Continue Reading