Tag: JAVA sOLUTION
2020 makeup Java solutions || BIM STUDY NOTES
Q.no 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//11. program to check whether the number is palindrome or not import java.util.Scanner; class Main{ public static void main(Sting[]args){ Scanner sc= new Scanner(System.in); System.out.println("ENter a number"); int num = sc.nextInt(); int number=num; int rev=0; while(num!=0){ int temp=num%10; rev = rev*10 + temp; num=num/10; } if(rev==number){ System.out.println("It is palindrome."); else System.out.println("It isnot palindrome"); } } } |
Q.no 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 30 31 32 33 34 35 36 37 38 39 40 |
class ThreadA extends Thread{ public void run(){ String []s={"eagle","pigeon","parrot", "sparrow","crow"}; for(x:s) { try{ thread.sleep(1000); } catch(InterruptedException e) { } System.out.println(x); } } } class ThreadB extends Thread{ public void run(){ String []s1={"Tiger","Elephant","monkey"}; for(d:s1) { try{ thread.sleep(2500); } catch(InterruptedException e) { } System.out.println(d); } } } class MainThread { public static void main(String[] args) { ThreadA t1=new ThreadA(); ThreadB t2=new ThreadB(); t1.start(); t2.start(); } } |
Q.no 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Rectangle{ int length , breadth; Rectangle(int l , int b) { length=l; breadth=b; } int Calculate(){ return length*breadth; } } class MainMethod extends Rectangle{ public static void main(String [] args){ Rectangle r=new Rectangle(10,20); int area=r.calculate(); System.out.println("Area of Rectangle" +area); } } |
Q.no 14
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 |
interface Calculate{ int add(int a, int b); int sub(int a, int b); int mul(int a, int b); int div(int a, int b); } class BasicCalculator implements calculate{ public int add(int a, int b) { return a+b; } public int sub(int a, int b) { return a-b; } public int mul(int a, int b) { return a*b; } public int div(int a, int b){ return a/b; } BasicCalculator b=new BasicCalculator(); int addition=b.add(); int subtraction=b.sub(); int multiplication=b.mul(); int division =b.div(); } } |
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 |
import java.util.Scanner; class Person { public static void main(String[] args) { String name; int age; char Gender; Scanner s=new Scanner(System.in); int a[]=new int[10]; for(i=0;i<10;i++) { System.out.println("Enter Your name:"); name=s.nextLine(); System.out.println("Enter age:"); age=s.nextInt(); System.out.println("Enter your Gender:"); Gender=s.next(); System.out.println("Name :"+name); System.out.println("Age:"+age); System.out.println("Gender:"+Gender); } } } |
JAVA 2017 Old Paper Solutions || BIM STUDY NOTES
Year 2017 Q.no 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public class tu17Q11 { public static void main(String[] args) { int n,i; System.out.println("Enter the number of numbers to enter"); Scanner sn=new Scanner(System.in); n=sn.nextInt(); System.out.println("Enter the numbers"); int num[]; for(i=0;i<n;i++){ num[i]=sn.nextInt(); if(num[i]%2==0&&num[i]%3==0){ System.out.println(num[i]); } } } } |
Q.no 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 30 31 32 33 34 35 36 37 38 |
/** * * @author bim study notes */ class Student { int roll_no; public void readRoll(int r){ roll_no=r; } public void displayRoll(){ System.out.println(roll_no); } } class Test extends Student{ int markJava,markWeb; public void readMarks(int mj,int mw){ markJava=mj; markWeb=mw; } public void displayMarks(){ System.out.println("Java:"+markJava+" "+"Web:"+markWeb); } } class Results extends Test{ int total; public void calculate(){ total=markJava+markWeb; } public void display(){ System.out.println("The total marks is :"+total); } public static void main(String[] args) { Results obj=new Results(); obj.readRoll(1); obj.readMarks(49,40); obj.calculate(); obj.displayRoll(); obj.displayMarks(); obj.display(); } } |
Q.no 13
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 |
interface Shape{ public void get_data(int l,int b); public void display_area(); } class Rectangle implements Shape{ int length,breadth,area; public void get_data(int l,int b){ length=l; breadth=b; } public void display_area(){ area=length*breadth; System.out.println("The area of rectangle is:"+area); } } class Square implements Shape{ int length,breadth,area; public void get_data(int l,int b) { length=l; } public void display_area(){ area=length*length; System.out.println("The area of Square is:"+area); } } public class tu17Q13 { public static void main(String[] args) { Rectangle obj=new Rectangle(); obj.get_data(10, 20); obj.display_area(); Square obj1=new Square(); obj1.get_data(10, 0); obj1.display_area(); } } |
Q.no 14
1 2 3 4 5 6 7 8 9 10 11 |
public class tu17Q14 { public static void main(String[] args) { String []country={"Nepal","USA","Australia","Brazil","Paragua","Canada"}; int i; for(i=0;i<6;i++){ if(country[i].endsWith("a")){ System.out.println(country[i]); } } } } |
1 |
17.Explain user defined exception in java with a suitable example. In java we can create our own exception class and throw that exception using throw keyword. These exceptions are known as user-defined or custom exceptions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class JavaException{ public static void main(String args[]){ try{ throw new MyException(2); // throw is used to create a new exception and throw it. } catch(MyException e){ System.out.println(e) ; } } } class MyException extends Exception{ int a; MyException(int b) { a=b; } public String toString(){ return ("Exception Number = "+a) ; } } |
Java Old Paper solution
Model Question 2015 2016 2017 2018 2019 2020 Makeup 2022 SAQ Pre Board
Continue Reading