0% found this document useful (0 votes)
131 views5 pages

XI Assignment

The document contains 22 questions asking to write Java programs to perform various tasks like: 1) Generate weekday name from number 2) Compare floating numbers up to 3 decimal places 3) Find number of days in a month 4) Identify if character is vowel or consonant 5) Display cubes of numbers up to given integer 6) Print patterns like triangles and diamonds 7) Check for certain types of numbers like Disarium, Pronic, Harshad 8) Find greatest common divisor of two numbers 9) Remove duplicate characters from input word The questions cover basic programming concepts like conditional statements, loops, patterns, strings and numeric operations.

Uploaded by

Prashant Dangi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views5 pages

XI Assignment

The document contains 22 questions asking to write Java programs to perform various tasks like: 1) Generate weekday name from number 2) Compare floating numbers up to 3 decimal places 3) Find number of days in a month 4) Identify if character is vowel or consonant 5) Display cubes of numbers up to given integer 6) Print patterns like triangles and diamonds 7) Check for certain types of numbers like Disarium, Pronic, Harshad 8) Find greatest common divisor of two numbers 9) Remove duplicate characters from input word The questions cover basic programming concepts like conditional statements, loops, patterns, strings and numeric operations.

Uploaded by

Prashant Dangi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Holiday Homework

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

3. Write a Java program to find the number of days in a month

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 :

Number is : 1 and cube of 1 is : 1


Number is : 2 and cube of 2 is : 8
Number is : 3 and cube of 3 is : 27
Number is : 4 and cube of 4 is : 64

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

11. Write a program in Java to display the pattern like a diamond.


Input number of rows (half of the diamond) : 7
Expected Output :

*
***
*****
*******
*********
***********
**************
***********
*********
*******
*****
***
*
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

13. Write a java program to generate a following *'s triangle.

Input the number: 6


Expected Output :

******
*****
****
***
**
*
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.

For example 135 is a DISARIUM


(Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc)
17. Write a Java program that accepts three numbers and prints "All numbers are equal" if all three numbers are
equal, "All numbers are different" if all three numbers are different and "Neither all are equal or different"
otherwise.

Input first number: 2564


Input second number: 3526
Input third number: 2456
Expected Output :

All numbers are different

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).

The first few pronic numbers are:


0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.

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)

The first few Harshad numbers in base 10 are:


1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100,
102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152, 153, 156, 162, 171, 180, 190, 192,
195, 198, 200 etc.
21. Write a Program in Java to input 2 numbers and find their Greatest Common Divisor (GCD).

Note: If the 2 numbers are 54 and 24, then the divisors (factors) of 54 are: 1, 2, 3, 6, 9, 18, 27, 54.

Similarly the divisors (factors) of 24 are: 1, 2, 3, 4, 6, 8, 12, 24.

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 ?

Example : By using Successive Division Method, find the GCD of 24 & 18 ?

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

You might also like