import java.util.*;
public class assignment_9
{
void num_calc(int num,char ch)
{
int cube =1;
int sq = 1;
if(ch=='c' || ch=='C')
{cube = num*num*num;
System.out.println("Cube of " + num + " = "+ cube);
}
else
{sq = num*num;
System.out.println("Square of " + num + " = "+ sq);
}
}
void num_calc(int a,int b,char ch)
{
int prod =1;
int sum = 0;
if(ch=='p')
{prod = a*b;
System.out.println("Product of " + a + " and "+ b+" = "+ prod);
}
else
{sum=a+b;
System.out.println("Sum of "+ a + " and "+ b+" = "+ sum);
}
}
void num_calc(String s1,String s2)
{
if(s1.equals(s2))
System.out.println("The strings are equal");
else
System.out.println("The strings are not equal");
}
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the integer for the first function : ");
int a = sc.nextInt();
System.out.print("Enter the character for the first function : ");
char c = sc.next().charAt(0);
System.out.println("Enter two integers for the second function : ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
System.out.print("Enter the character for the second function : ");
char ch = sc.next().charAt(0);
System.out.println("Enter the first string for the third function : ");
String st1 = sc.next();
System.out.println("Enter the second string for the third function : ");
String st2 = sc.next();
assignment_9 obj = new assignment_9();
obj.num_calc(a,c);
obj.num_calc(n1,n2,ch);
obj.num_calc(st2,st1);
}
}
public class assignment_9
{
void num_calc(int num,char ch)
{
int cube =1;
int sq = 1;
if(ch=='c' || ch=='C')
{cube = num*num*num;
System.out.println("Cube of " + num + " = "+ cube);
}
else
{sq = num*num;
System.out.println("Square of " + num + " = "+ sq);
}
}
void num_calc(int a,int b,char ch)
{
int prod =1;
int sum = 0;
if(ch=='p')
{prod = a*b;
System.out.println("Product of " + a + " and "+ b+" = "+ prod);
}
else
{sum=a+b;
System.out.println("Sum of "+ a + " and "+ b+" = "+ sum);
}
}
void num_calc(String s1,String s2)
{
if(s1.equals(s2))
System.out.println("The strings are equal");
else
System.out.println("The strings are not equal");
}
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the integer for the first function : ");
int a = sc.nextInt();
System.out.print("Enter the character for the first function : ");
char c = sc.next().charAt(0);
System.out.println("Enter two integers for the second function : ");
int n1 = sc.nextInt();
int n2 = sc.nextInt();
System.out.print("Enter the character for the second function : ");
char ch = sc.next().charAt(0);
System.out.println("Enter the first string for the third function : ");
String st1 = sc.next();
System.out.println("Enter the second string for the third function : ");
String st2 = sc.next();
assignment_9 obj = new assignment_9();
obj.num_calc(a,c);
obj.num_calc(n1,n2,ch);
obj.num_calc(st2,st1);
}
}
No comments:
Post a Comment