In: Computer Science
10.
System.out.println("Value of |-13.75| is " + Math.abs(-13.75));
PROGRAM IMPLEMENTATION
import java.lang.*;
public class demo
{
public static void main(String[] args)
{
System.out.println("Value of |-13.75| is " + Math.abs(-13.75));
}
}
OUTPUT
11)
public static int diff(int a, int b)
{
return a-b;
}
12. program IMPLEMENTATION
import java.lang.*;
import java.util.Scanner;
public class demo
{
public static int diff(int a, int b)
{
return a-b;
}
public static void main(String[] args)
{
int x,y;
Scanner sc = new Scanner(System.in);//declare the
scanner object
//input the value of x
System.out.println("Enter X value :");
x = sc.nextInt();
//input the value of y
System.out.println("Enter Y value :");
y = sc.nextInt();
//DISPLAY THE DIFFERENCE
System.out.println("Difference of "+x+" and "+y+ " is
"+diff(x,y));
}
}
OUTPUT
13.
//area method takes three parameters and find the area
of rectangular prism
public static double area(double len,double wid, double
height)
{
double area;
area= 2*(wid*len + height*len + height*wid);
return area;
}
//check method will return true if number is multiple of 5
otherwise returns false.
public static boolean check(int a)
{
if(a%5==0)
return true;
else
return false;
}
//rating method will return a character for rating
public static char rating()
{
Scanner sc = new Scanner(System.in);//declare the scanner
object
char c;
System.out.println("Enter the rating(E/O/G/N)");
c = sc.next().charAt(0);
return c;
}
PROGRAM IMPLEMENTATION
import java.lang.*;
import java.util.Scanner;
public class demo
{
//check method will return true if number is multiple of 5
otherwise returns false.
public static boolean check(int a)
{
if(a%5==0)
return true;
else
return false;
}
//rating method will return a character for rating
public static char rating()
{
Scanner sc = new Scanner(System.in);//declare the scanner
object
char c;
System.out.println("Enter the rating(E/O/G/N)");
c = sc.next().charAt(0);
return c;
}
//area method takes three parameters and find the area of
rectangular prism
public static double area(double len,double wid, double
height)
{
double area;
area= 2*(wid*len + height*len + height*wid);
return area;
}
public static void main(String[] args)
{
int x,y;
char c;
double l,w,h;
Scanner sc = new Scanner(System.in);//declare the scanner object
//input the value of x
System.out.println("Enter X value :");
x = sc.nextInt();
//check whether x is multipleof 5 or not
if(check(x))
System.out.println(x+" is multiple of 5");
else
System.out.println(x+" is not multiple of 5");
System.out.println("Your rating is "+ rating());
System.out.println("Enter the length of rectangular
prism");
l = sc.nextDouble();
System.out.println("Enter the width of rectangular
prism");
w = sc.nextDouble();
System.out.println("Enter the height of rectangular
prism");
h = sc.nextDouble();
System.out.println("Area of rectangular prism is : "+ area(l,w,h) +
"Sq. Units.");
}
}
OUTPUT