Skip to main content

Posts

Showing posts from January, 2023

Difference between Alter and Update

Difference between ALTER and UPDATE ALTER * It is a DDL. *   It is used for adding, deleting and modifying attributes of the table. *   Changes are made to the table structure. *   By default, all the values in the tuple are initialized as null if the ALTER command is used. UPDATE *   It is a DML. *   It is used for updating the data in the existing table. *   Changes are made to the data. *   It sets the specified value to the tuple if update command is used.

four methods overload these methods

Write a program in java which has the following classes and methods:  Class : OverloadDemo Methods : test() Declare four methods with the same name “test()” and overload these methods class OverloadDemo{  public void test(){  System.out.println("It's a test method for null.");  }  public void test(int n){  System.out.println("It's a test method for displaying the int value "+n);  }  public void test(double d){  System.out.println("It's a test method for displaying the double value "+d);  }  public void test(String s){  System.out.println("It's a test method for displaying the String "+s);  }  }  class overClass{  public static void main(String[] args) {  OverloadDemo old = new OverloadDemo();  old.test();  old.test(12);  old.test(25.35);  old.test("Subham");  }  } OUTPUT: It's a test method for null. It's a test method for displaying the int value 12 It's a test method for displaying the double value 25.35 It

creating object for class triangle

Define a class named triangle as described below: Data members: 1) side1 2) Side2 3) side3 4) angle1, angle2, angle3 Methods : 1) constructors 2) trianglePerimeter() 3) triangleArea() 4) isoceles( ) 5) equilateral( ) 6) rightAngled() 7) scalene() Test this class by creating an object for the class triangle. class triangle{  public double s1;  public double s2;  public double s3;  public double a1;  public double a2;  public double a3;  public triangle(){  }  public double trianglePerimeter(){  return this.s1+this.s2+this.s3;  }  public double triangleArea(){  double s = trianglePerimeter()/2;  double a=s*(s-this.s1)*(s-this.s2)*(s-this.s3);  return Math.pow(a, 0.5);  }  public void isisoceles(){  if(this.s1==this.s2 || this.s2==this.s3 || this.s3==this.s1)  System.out.println("Triangle is isosceles.");  else System.out.println("Triangle is not isosceles.");  }  public void equilateral(){  if(this.s1==this.s2 && this.s2==this.s3 && this.s3==this.s1) 

creating object invoking various methods

Define a class named College as described below:  Data Members: 1) collegeName 2) principalName 3) place Methods : 1) constructor. 2) display() to display the collegeName, principalName, and the place. Test this class by creating an object and then invoking the various methods. class collegeName{  public String collegeName;  public String PrincipalName;  public String place;  public collegeName(){  }  public void display(){  System.out.println("College name is "+this.collegeName);  System.out.println("Principal name is "+this.PrincipalName);  System.out.println("Place is "+this.place);  }  }  class displayName{  public static void main(String[] args) {  collegeName c = new collegeName();  c.collegeName="Siliguri Institute of Technology";  c.PrincipalName="Dr. Mithun Chakraborty";  c.place="Siliguri";  c.display();  }  } OUTPUT: College name is Siliguri Institute of Technology Principal name is Dr. Mithun Chakraborty Place is S

circumference and arc Length of the circle

Define a class named Circle as described below: Data Members: radius, angle Methods : 1) constructor. 2) circleCircumference() to compute the circumference of the circle. 3) arcLength() to compute the length of an arc for a given angle. Within the main( ) method of the class named CircleDemo, create an object of the class Circle.  Compute the circle’s circumference when the radius is 20 and the arc length when the angle is 90. class Circle{ public double radius; public double angle; public Circle(double radius, double angle){ } public double circleCircumference(double radius){ return 2*Math.PI*radius; } public double arcLength(double radius, double angle){ return radius*angle; } } public class CircleDemo { public static void main(String[] args) { Circle c1 = new Circle(20,90); System.out.println("The Circumference of the Circle is "+c1.circleCircumference(20)); System.out.println("The arc Length of the circle is "+c1.arcLength(20,90)); } } OUTPUT: The Circumference

Define abstract class in java

Define a abstract class named Geometry as described below:  Data Member: pi Abstract Method: calculate() Now create two sub classes , cylinder and Rhombus from “Geometry” class and calculate the volume for cylinder and area for rhombus. import java.util.Scanner;  class abstractGeo {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the Height of the cylinder : ");  double n1 = sc.nextDouble();  System.out.println("Enter the Radius of the cylinder : ");  double n2 = sc.nextDouble();  System.out.println("Enter the 1st diagonal of the Rhombus : ");  double n3 = sc.nextDouble();  System.out.println("Enter the 2nd diagonal of the Rhombus : ");  double n4 = sc.nextDouble();  cylinder c = new cylinder();  System.out.println("The volume of Cylinder is : " + c.calculate(n1,n2));  System.out.println("-------------------------------------------------");  Rhombus r = new Rhombus(); 

Define a class employee with the following members to compute the salary slip of an employee.

Define a class employee with the following members to compute the salary slip of an employee. Members: Empno., Name, Basic pay(salary), House rent allowance(HRA), Dearness allowance(DA),Medical Allowance(MA), Gross pay(GP). Member Function: calc() - calculation HRA - 10% of salary DA - 55.5% of salary MA - 6%of salary GP - salary +HRA+DA+MA Display() - to output in given format. Salary Slip Employee number : Name : Basic Pay : House rent allowance (HRA) : Dearness allowance (DA) : Income tax (IT) : Gross pay(GP) : import java.util.Scanner;  class salarySlip{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter Employee Name : ");  String name = sc.next();  System.out.println("Enter Employee ID : ");  String empId = sc.next();  System.out.println("Enter The Salary: ");  double sal = sc.nextDouble();  employee emp1=new employee();  emp1.setName(name);  emp1.empNo(empId);  emp1.setSalary(sal);  emp1.Displa

Create one Box class and find out area and volume of a box (Using parameterized method, And method should have no return type)

Create one Box class and find out area and volume of a box (Using parameterized method, And method should have no return type). import java.util.Scanner;  public class volumeBox {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the value of length: ");  double l=sc.nextDouble();  System.out.println("Enter the value of width: ");  double w=sc.nextDouble();  System.out.println("Enter the value of height: ");  double h=sc.nextDouble();  box b1=new box();  System.out.println("The area of the box is "+b1.area(l, w, h));  System.out.println("The volume of the box is "+b1.volume(l, w, h));  sc.close();  }  }  class box{  public double area(double l,double w,double h){  return 2*(l*w+l*h+h*w);  }  public double volume(double l,double w,double h){  return l*w*h;  }  } OUTPUT: Enter the value of length: 5 Enter the value of width: 6 Enter the value of height: 4 The area of the box is 148.

Write a program to print the pyramid in Java

Write a program to print the following pyramid.      *     **   ****  ***** ****** import java.util.Scanner;  class pyramid{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the range of the pyramid : ");  int n = sc.nextInt();  for(int i=1;i<=n;i++){  for(int j=1;j<=n-i;j++){  System.out.print(" ");  }  for(int k=1;k<=2*i-1;k++){  System.out.print("* ");  }  System.out.println();  }  sc.close();  }  } OUTPUT: Enter the range of the pyramid : 5      *     **   ****  ***** ******

Write a program to print the following triangle

Write a program to print the following triangle. * ** **** ***** ****** import java.util.Scanner;  class triangle{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the range of the pyramid : ");  int n = sc.nextInt();  for(int i=n;i>=0;i--){  for(int j=i;j<n;j++){  System.out.print("* ");  }  System.out.println();  }  sc.close();  }  } OUTPUT: Enter the range of the pyramid : 5 * ** **** ***** ******

Write a program in java to search a number from a list

Write a program in java to search a number from a list. import java.util.Scanner;  class searchNumber{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  int A[]={1,2,6,4,8,7,9};  System.out.println("Enter the number to search : ");  int n=sc.nextInt();  searchItem(A, n);  sc.close();  }  public static void searchItem(int A[],int n){  for(int i=0;i<A.length;i++){  if(A[i]==n){  System.out.println(n+" is present at index "+i);  break;  }  }  }  } OUTPUT: Enter the number to search : 4 4 is present at index 3

Write a Program in java to sort a list of items in ascending order

Write a Program in java to sort a list of items in ascending order. class sortList{  public static void main(String[] args) {  int A[]={1,2,6,4,8,7,9};  System.out.println("Original List : ");  printArray(A);  System.out.println();  assendingOrder(A);  System.out.println("List in ascending order : ");  printArray(A);  }  public static void printArray(int A[]){  for(int i=0;i<A.length;i++){  System.out.print(A[i]+"\t");  }  }  public static void assendingOrder(int A[]){  int a;  for(int i=0;i<A.length;i++){  for(int j=i;j<A.length;j++){  if(A[i]>A[j]){  a=A[i];  A[i]=A[j];  A[j]=a;  }  }  }  }  } OUTPUT: Original List : 1     2     6     4     8     7     9 List in ascending order : 1     2     4     6     7     8     9

Write a Program in java to accept a number and check whether the number is palindrome or not

Write a Program in java to accept a number and check whether the number is palindrome or not. import java.util.Scanner;  public class palindromeNumber {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the number : ");  int n = sc.nextInt();  isPallindrome(n);  sc.close();  }  public static void isPallindrome(int n) {  int num = n;  int reverse = 0;  while (num > 0) {  int rem = num % 10;  reverse = reverse * 10 + rem;  num /= 10;  }  if (reverse == n)  System.out.println(n + " is Palindrome Number.");  else System.out.println(n + " is not Palindrome Number.");  }  } OUTPUT:   Enter the number : 1331 1331 is Palindrome Number

Given an array S of n integers, Write a Java Program to find out whether there exists a pair of integers in S whose sum is equal to a given integer x.

Given an array S of n integers, Write a Java Program to find out whether there exists a pair of integers in S whose sum is equal to a given integer x. import java.util.Scanner;  class pairSum{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the number : ");  int n = sc.nextInt();  int a[]={1,2,3,6,10};  checkPair(a, n);  sc.close();  } public static void checkPair(int A[],int x){  for(int i=0;i<(A.length-1);i++){  for(int j=i+1;j<A.length;j++){  if(A[i]+A[j]==x)  System.out.println("Pair with a given sum "+x+" is ("+A[i]+" + "+A[j]+")");  }  }  }  } OUTPUT: Enter the number :  3 Pair with a given sum 3 is (1+2)

Write a java program which has various types of constructor and overload these constructors when the object is being created of that class.

Write a java program which has various types of constructor and overload these constructors when the object is being created of that class. class variousConstructor {  public static void main(String[] args) {  constructor c1 = new constructor();  constructor c2 = new constructor(23);  constructor c3 = new constructor(45.6);  }  }  class constructor {  public constructor() {  System.out.println("It's 1st constractor.");  }  public constructor(int n1) {  System.out.println("It's constractor with integer variable which is " + n1);  }  public constructor(double d1) {  System.out.println("it's a constractor with double variable which is " + d1);  }  public constructor(float f1) {  System.out.println("It's a constractor with float variable which is " + f1);  }  } OUTPUT: It's 1st constractor. it's a constractor with double variable which is 23 It's a constractor with float variable which is 45.6

Write a program to reverse all the digits of a given integer.

Write a program to reverse all the digits of a given integer. import java.util.Scanner;  class assignment1{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the number : ");  int n = sc.nextInt();  reverseNum(n);  sc.close();  }  public static void reverseNum(int num) {  int n = num;  int rev = 0;  while (n > 0) {  int rem = n % 10;  rev = rev * 10 + rem;  n /= 10;  }  System.out.println("Reverse of " + num + " is " + rev);  }  } OUTPUT: Enter the number : 1234 Reverse of 1234 is 4321

Write a program to find out whether a number is prime or not.

Write a program to find out whether a number is prime or not. import java.util.Scanner;  public class primeNumber {    public static void main(String[] args) {      Scanner sc = new Scanner(System.in);      System.out.println("Enter the number : ");      int n = sc.nextInt();      if (isPrime(n)) {        System.out.println(n + " is Prime.");        } else {        System.out.println(n + " is not Prime.");      }      sc.close();    }  public static boolean isPrime(int n) {     for (int i = 2; i <= n / i; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }  } OUTPUT: Enter the number : 2 2 is Prime.

Write a Program in java that prints all real solutions to the quadratic equations ax2+bx+c=0. Read a,b,c and use the quadratic formula. If the discriminate b2-4ac is negative, display a message stating there are no real solutions.

Write a Program in java that prints all real solutions to the quadratic equations ax2+bx+c=0. Read a,b,c and use the quadratic formula. If the discriminate b2-4ac is negative, display a message stating there are no real solutions. import java.util.Scanner;  class quads{   public static void main(String[] args) {    Scanner sc = new Scanner(System.in);    System.out.println("Eneter the value of a : ");    double a = sc.nextDouble();    System.out.println("Enter the value of b : ");    double b = sc.nextDouble();    System.out.println("Enter the value of c : ");    double c = sc.nextDouble();    double d = b * b - 4 * a * c;    if (d > 0.0) {     double r1 = (-b + Math.pow(d, 0.5)) / (2.0 * a);     double r2 = (-b - Math.pow(d, 0.5)) / (2.0 * a);     System.out.println("The roots are " + r1 + " and " + r2);    }    else if (d == 0.0) {     double r1 = -b / (2.0 * a);     System.out.println("The root is " + r1);    }   else { 

Write a Program in java to find the GCD of two numbers

Write a Program in java to find the GCD of two numbers. import java.util.Scanner;  public class gcdProgram {  public static void main(String[] args) {   Scanner sc = new Scanner(System.in);   System.out.println("Enter two numbers : ");   int n1=sc.nextInt();   int n2=sc.nextInt();   int gcd=0;   for(int i=1;i<=n1 && i<=n2;i++){    if(n1%i==0 && n2%i==0){     gcd=i;    }   }   System.out.println("The GCD of "+n1+" and "+n2+" = "+gcd);    sc.close();   }  } OUTPUT: Enter two numbers : 9 12 The GCD of 9 and 12 = 3