English

Define a class to overload the method print() as follows: void print ( ) – To print the given format using nested loops. @#@#@ @#@#@ @#@#@ @#@#@ double print(double a, double b) – To display - Computer Applications

Advertisements
Advertisements

Question

Define a class to overload the method print() as follows:

void print ( ) – To print the given format using nested loops.

@#@#@

@#@#@

@#@#@

@#@#@

double print(double a, double b) – To display the sum of numbers between a and b with difference of 0.5.

e.g. if a = 1.0, b = 4.0

output is: 1.0 + 1.5 + 2.0 + 2.5 + ……………. + 4.0

int print(char ch1, char ch2) – compare the two characters and return the ASCII code of the largest character.

Case Study
Advertisements

Solution

import java.util.*;
public class Overloadprint
{
public void print()
  {
     for (int i=0;i<4;i++)
     {
        for (int j=0;j<4;j++)
        {  if (j%2=0)
              System.out.print("@");
         else
              System.out.print("#");
  }
System.out.println();
 }
}
public void print(double a, double b)
{
   double s=0.0;
   for(double p=a;p<=b;p+=0.5)
     s+=p;
  System.out.println(s);
}
 public void print(char c1,char c2)
{
   int a=c1;
   int b=c2;
   if (c1>c2)
    System.out.println(“ASCII code of higher
    character :" + a);
else
    System.out.println(“ASCII code of higher
    character :"+ b);
 }
}
shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Official Board
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×