October 23, 2018

To find the area of circle & Multiplication Table in Java

/**
 * To find the area of circle  & Multiplication Table
 */
package com.cfed.lambda;

import java.util.Scanner;

/**
 * @author consumerfed
 *
 */
public class ExampleJava {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
 
  ExampleJava ex = new ExampleJava();
  Scanner sc = new Scanner(System.in);
  System.out.println(" Enter the numbers ( to find the mul table upto 5 )");
  int mulNumb = sc.nextInt();
  ex.multiplicationTable(mulNumb);
  System.out.println(" Find the area of a circle ( Enter the radius)");
  float radius = sc.nextFloat();
  System.out.println(" The area of the circle with "+radius+" is "+ex.findAreaOfCircle(radius));;

 }



 private double findAreaOfCircle(float radius) {
  // TODO Auto-generated method stub
  double area = Math.PI * Math.sqrt(radius);
  return area;
 }



 private void multiplicationTable(int mulNumb) {
  // TODO Auto-generated method stub
  for(int i =1; i<=mulNumb; i++) {
   for(int j=1; j<=5;j++) {
    System.out.println(i+" x "+j+" = "+(i*j));
   }
  }
 }

}


Output

 Enter the numbers ( to find the mul table upto 5 )

4

1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10

3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15

4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20

 Find the area of a circle ( Enter the radius)

3

 The area of the circle with 3.0 is 5.441398092702653

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments