ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Specimen Paper



Share with a Friend

Solved 2024 ICSE Computer Science Specimen Paper

Class 10 - ICSE Computer Science Solved Specimen Papers

Method Overloading Program - ICSE 2024 Computer Science Specimen Paper

Question 8

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


void display(): To print the following format using nested loop.


1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

void display(int n): To print the square root of each digit of the given number.


Example:


n = 4329

Output:


3.0
1.414213562
1.732050808
2.0

import java.util.Scanner; class Overload{ public static void main(String[] args){ Scanner in = new Scanner(System.in); display(); System.out.print("n = "); int n = Integer.parseInt(in.nextLine()); display(n); } public static void display(){ for(int i = 1; i <= 5; i++){ for(int j = 1; j <= i; j++) System.out.print(j + " "); System.out.println(); } } public static void display(int n){ while(n > 0){ int digit = n % 10; System.out.println(Math.sqrt(digit)); n /= 10; } } }

Output

 
 OUTPUT  : 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 

n = 4329 3.0 1.4142135623730951 1.7320508075688772 2.0