XI Assignment
XI Assignment
Assignment - Computer
Class – XI
1. Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and displays the name
of the weekday.
Test Data
Input number: 3
Expected Output :
Wednesday
2. Write a Java program that reads in two floating-point numbers and tests whether they are the same up to three decimal
places
Test Data
Input floating-point number: 1256
Input floating-point another number: 3254
Expected Output :
They are different
Test Data
Input a month number: 2
Input a year: 2016
Expected Output :
February 2016 has 29 days
4. Write a Java program that takes the user to provide a single character from the alphabet. Print Vowel or Consonant,
depending on the user input. If the user input is not a letter (between a and z or A and Z), or is a string of length > 1, print an
error message.
Test Data
Input an alphabet: p
Expected Output :
Input letter is Consonant
5.Write a program in Java to display the cube of the number upto given an integer. Test Data
Input number of terms : 4
Expected Output :
6. Write a program in Java to make such a pattern like right angle triangle with a number which will repeat a
number in a row.The pattern is as follows
1
22
333
4444
7. Write a program in Java to display the pattern like right angle triangle with a number.
Test Data
Input number of rows : 10
Expected Output :
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
8. Write a program in Java to make such a pattern like right angle triangle with number increased by 1.The pattern
like :
1
23
456
7 8 9 10
9. Write a program in Java to make such a pattern like a pyramid with a number which will repeat the number in
the same row.
1
22
333
4444
10. Write a program in Java to print the Floyd's Triangle.
Input number of rows : 5
Expected Output :
1
01
101
0101
10101
*
***
*****
*******
*********
***********
**************
***********
*********
*******
*****
***
*
12. Write a Java program to display Pascal's triangle.
Input number of rows: 5
Expected Output :
Input number of rows: 5
1
11
121
1331
14641
******
*****
****
***
**
*
14. Write a java program to generate a following @'s triangle
Input the number: 6
Expected Output :
@
@@
@@@
@@@@
@@@@@
@@@@@@
15. Write a Java program to display the number rhombus structure. Test Data
Input the number: 7
Expected Output :
1
212
32123
4321234
543212345
65432123456
7654321234567
65432123456
543212345
4321234
32123
212
1
16. Write a Program in Java to input a number and check whether it is a Disarium Number or not.
Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal to
the original number.
18. Write a Java program to display the following character rhombus structure.
Input the number: 7
Expected Output :
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
19. Write a Program in Java to input a number and check whether it is a Pronic Number or Heteromecic Number
or not.
Pronic Number : A pronic number, oblong number, rectangular number or heteromecic number, is a number
which is the product of two consecutive integers, that is, n (n + 1).
20. Write a Program in Java to input a number and check whether it is a Harshad Number or Niven Number or
not..
Harshad Number : In recreational mathematics, a Harshad number (or Niven number), is an integer (in base 10)
that is divisible by the sum of its digits.
Let’s understand the concept of Harshad Number through the following example:
The number 18 is a Harshad number in base 10, because the sum of the digits 1 and 8 is 9 (1 + 8 = 9), and
18 is divisible by 9 (since 18 % 9 = 0)
The number 1729 is a Harshad number in base 10, because the sum of the digits 1 ,7, 2 and 9 is 19 (1 + 7 +
2 + 9 = 19), and 1729 is divisible by 19 (1729 = 19 * 91)
The number 19 is not a Harshad number in base 10, because the sum of the digits 1 and 9 is 10 (1 + 9 =
10), and 19 is not divisible by 10 (since 19 % 10 = 9)
Note: If the 2 numbers are 54 and 24, then the divisors (factors) of 54 are: 1, 2, 3, 6, 9, 18, 27, 54.
The numbers that these two lists share in common are the common divisors (factors) of 54 and 24: 1, 2, 3, 6.
The greatest (highest) of these is 6. That is the greatest common divisor or the highest common factor of 54 and
24.
Calculating HCF / GCD by Prime Factorisation Method is long and more time-consuming, and due to these
disadvantages new method was evolved by Mathematician namely, Successive Division Method
Under Successive Division Method, HCF / GCD = The Last Divisor of the given numbers .
Following example can guide you How to calculate HCF / GCD by Successive Division Method ?
22. Write a program to input a word from the user and remove the duplicate characters present in it.
Example:
INPUT – abcabcabc
OUTPUT – abc
INPUT – javaforschool
OUTPUT – javforschl
INPUT – Mississippi
OUTPUT – Misp