computes the cube of integer argument if choice ch is ‘c’/ ‘C’ otherwise finds its square.
void num_calc(int a,int b,char ch) with two integer arguments and one character
argument.It computes the product of integer arguments if ch is’p’ else adds the integers
void num_calc(String s1,String s2) with two string arguments,which prints whether the strings
are equal or not
import java.util.*;
class Assign9
{
void num_calc( int num, char ch )
{
int s = 0;
if(ch == 'c' )
s = num * num * num;
else
s = num * num;
System.out.println(" s = " + s );
}
void num_calc( int a, int b, char ch )
{
int s = 0;
if(ch == 'p' )
s = a * b;
else
s = a + b;
System.out.println(" s = " + s );
}
void num_calc( String s1, String s2 )
{
if(s1.equals(s2))
System.out.println("Both Strings are equal.");
else
System.out.println("Both Strings are not equal.");
}
public static void main(String args[ ])
{
Scanner sc = new Scanner(System.in);
Assign9 ob = new Assign9( );
ob.num_calc( 5, 'c' );
ob.num_calc( 8, 3, 'n' );
ob.num_calc( "String1", "String2" );
}
}
Output:
s = 125
s = 11
Both Strings are not equal.
No comments:
Post a Comment