design a overload function with one string argument and one integer argument it displays the character of even position of string if the integer is an even number otherwise displays the character of odd positions .Please answer correctly.
Answers
Answered by
2
import java.io.*;
import java.util.*;
class Overloaded1
{
void num_calc( int num, char ch )
{
int s = 0;
if(ch == 's' )
s = num * num;
else
s = num * 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);
Overloaded1 ob = new Overloaded1( );
ob.num_calc( 5, 's' );
ob.num_calc( 8, 3, 'n' );
ob.num_calc( "Bhavesh", "Solanki" );
}
}
Similar questions