Posts

Showing posts with the label JAVA

B.Tech. Computer Science and Engineering Notes - 3rd Year

Here, you can download ⬇️ notes of your choice. 😄😊👍 Semester 5 : Click the link below https://drive.google.com/drive/folders/11OyIz4QjwbdDh_o3HvyFMR3ng9rbPkaU?usp=sharing Semester 6 : Click the link below https://drive.google.com/drive/folders/1-Vm4pbtH1ZaHnzOx2oJbcP96iwrE4waS?usp=sharing
Q2. Write a program in JAVA to count the number of digits in a given number. Example 1: Input: 654845  Output: The number of digits in the given number are 6 Example 2: Input: 6845  Output: The number of digits in the given number are 4 Solution:  import java.util.Scanner; public class CountingDigitsInInteger {    public static void main(String args[]){       Scanner sc = new Scanner(System.in);       int count = 0;       System.out.println("Enter a number ::");       int num = sc.nextInt();       while(num!=0){          num = num/10;          count++;       }       System.out.println("Number of digits in the entered integer are :: "+count);    } }
Q1. Write a program in JAVA to calculate the area of triangle, circle, square and rectangle. However, you need to ensure that the preceding set of functionalities must be achieved by implementing abstraction. Solution: // Java program to illustrate the // concept of Abstraction abstract class Shape { String color; // these are abstract methods abstract double area(); public abstract String toString(); // abstract class can have the constructor public Shape(String color) { System.out.println("Shape constructor called"); this.color = color; } // this is a concrete method public String getColor() { return color; } } class Circle extends Shape { double radius; public Circle(String color, double radius) { // calling Shape constructor super(color); System.out.println("Circle constructor called"); this.radius = radius; } @Override double area() { return Math.PI * Math.pow(radius, 2); } @Override public String ...