Menu
Topics Index
...
`

Intermediate Level Test 3 has these questions


Print all the factors of a given number

Write a program to print the factors of the given number. The numbers should be separated by comma.
Input (Integer) Printed Output (Commas are also important and there are no spaces in output)
3 1,3,
8 1,2,4,8,
24 1,2,3,4,6,8,12,24,
class PrintFactorsOfNumber

{    public static void main(String s[])
    {
        printFactorsOfNumber(25);

    }


public static void printFactorsOfNumber(int number)
{
//Write code here to print the factors of the given number.
}
}



Sum of Even Numbers Till Given Number

Write a program to find the sum of all even numbers till a given number.
Input Output
7 2 + 4 + 6 = 12
15 2 + 4 + 6 + 8 + 10 + 12 + 14 = 56
class SumOfEvenNumbers

{    public static void main(String s[])
    {
        System.out.println("Sum of even numbers till 5 is " + sum_of_even_numbers(5));

    }


public static int sum_of_even_numbers(int input)
{
int output = 0;
//Write code here to find the sum of even numbers till input and assign it to output
return output;
}
}



Print String Pyramid

Write a program to print the following character pyramid using the input string. Spaces at the beginning of the line and spaces between characters are important. Use System.out.println or System.out.print for printing.
Input (String) Printed Output
India      I
    I n
   I n d
  I n d i
 I n d i a
campus       c
     c a
    c a m
   c a m p
  c a m p u
 c a m p u s
class PrintFormation

{    public static void main(String s[])
    {
        printFormation("India");

    }


public static void printFormation(String name)
{
//Write code here to print string pyramid using name. Use System.out.println or System.out.print for printing.
}
}



Print Number Formation124

Write a program to print the following formation depending upon size of the matrix. Use System.out.println or System.out.print for printing.
Input (Integer) Printed Output
4
2 2 
3 3 3 
4 4 4 4
7
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
for eg. if the input is 4 it should print for eg. if the input is 5 it should print
class PrintFormation

{    public static void main(String s[])
    {
        printFormation(5);

    }


public static void printFormation(int size)
{
//Write code here to print the required formation depending upon the size. Use System.out.println or System.out.print for printing.
}
}



Find Maximum Of Three Numbers

Write a program to get the maximum value of 3 numbers.
class FindMaxNumber

{    public static void main(String s[])
    {
        System.out.println("The maximum number in 3, 7 and 10 is " + maximum(3, 7, 10));

    }


public static int maximum(int a, int b, int c)
{
int maximum = 0;
//Write code here to get the maximum value in a, b, c and assign it to result.
return maximum;
}
}



© meritcampus 2019

All Rights Reserved.

Open In App