Some Java Programs to practice.(Part 3)

Codynn
5 Min Read

I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.

Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US

26. Write a program to display area of circle.

import java.util.Scanner;

class AreaOfCircle {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the radius of circle");
       double radius = sc.nextDouble();
       double area = Math.PI * radius * radius;
       System.out.println("Area of circle is " + area);
   }
}

27. Write a program to display total surface area and volume of cylinder.

import java.util.Scanner;

class SurfaceAreaAndVolumeOfCylinder {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the radius of cylinder");
       double radius = sc.nextDouble();
       System.out.println("Enter the height of cylinder");
       double height = sc.nextDouble();
       double surfaceArea = 2 * Math.PI * radius * (radius + height);
       double volume = Math.PI * radius * radius * height;
       System.out.println("Surface area of cylinder is " + surfaceArea);
       System.out.println("Volume of cylinder is " + volume);
   }
}

28. Write a program to ask the user to enter the marks in any four subject and display whether the user is pass or fail.

import java.util.Scanner;

class Marks {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the marks in English");
       int english = sc.nextInt();
       System.out.println("Enter the marks in Maths");
       int maths = sc.nextInt();
       System.out.println("Enter the marks in Science");
       int science = sc.nextInt();
       System.out.println("Enter the marks in Social");
       int social = sc.nextInt();
       int total = english + maths + science + social;
       double percentage = total / 4.0;
       if (percentage >= 35) {
           System.out.println("Pass");
       } else {
           System.out.println("Fail");
       }
   }
}

29. Write a program to display volume of cylinder.

import java.util.Scanner;

class VolumeOfCylinder {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the radius of cylinder");
       double radius = sc.nextDouble();
       System.out.println("Enter the height of cylinder");
       double height = sc.nextDouble();
       double volume = Math.PI * radius * radius * height;
       System.out.println("Volume of cylinder is " + volume);
   }
}

30. Write a program to display volume of hemisphere.

import java.util.Scanner;

class VolumeOfHemisphere {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the radius of hemisphere");
       double radius = sc.nextDouble();
       double volume = (4.0 / 3.0) * Math.PI * (radius * radius * radius);
       System.out.println("Volume of hemisphere is " + volume);
   }
}

31. Write a program to display total surface area and volume of cube.

import java.util.Scanner;

class SurfaceAreaAndVolumeOfCube {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the side of cube");
       double side = sc.nextDouble();
       double surfaceArea = 6 * (side * side);
       double volume = side * side * side;
       System.out.println("Surface area of cube is " + surfaceArea);
       System.out.println("Volume of cube is " + volume);
   }
}

32. Write a program to display area of triangle.

import java.util.Scanner;

class AreaOfTriangle {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the base of triangle");
       double base = sc.nextDouble();
       System.out.println("Enter the height of triangle");
       double height = sc.nextDouble();
       double area = (base * height) / 2;
       System.out.println("Area of triangle is " + area);
   }
}

33. Write a program to display volume of cube.

import java.util.Scanner;

class VolumeOfCube {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the side of cube");
       double side = sc.nextDouble();
       double volume = side * side * side;
       System.out.println("Volume of cube is " + volume);
   }
}

34. Write a program to display perimeter of square.

import java.util.Scanner;

class PerimeterOfSquare {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the side of square");
       double side = sc.nextDouble();
       double perimeter = 4 * side;
       System.out.println("Perimeter of square is " + perimeter);
   }
}

35. Write a program to display area of parallelogram.

import java.util.Scanner;

class AreaOfParallelogram{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the base of parallelogram");
       double base = sc.nextDouble();
       System.out.println("Enter the height of parallelogram");
       double height = sc.nextDouble();
       double area = base * height;
       System.out.println("Area of parallelogram is " + area);
   }
}
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *