0% found this document useful (0 votes)
8 views12 pages

Java 50 Programming Questions

This document contains 50 Java programming questions designed for 10th standard students, covering various topics such as basic output, control structures, loops, patterns, and number programs. Each question requires students to write complete Java programs with proper structure and comments. The questions range from simple tasks like printing text to more complex problems involving calculations and pattern generation.
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)
8 views12 pages

Java 50 Programming Questions

This document contains 50 Java programming questions designed for 10th standard students, covering various topics such as basic output, control structures, loops, patterns, and number programs. Each question requires students to write complete Java programs with proper structure and comments. The questions range from simple tasks like printing text to more complex problems involving calculations and pattern generation.
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

Java Programming

50 Programming Questions
Class: 10th Standard | Topics: All Java Basics | Marks: 50
Name: _________________________ Roll No: ________ Date: __________

Instructions: Write complete Java programs for each question. Show proper class structure, main method, and
comments where needed.
Sections: Basic Output | If-Else-If | Switch-Case | For Loop | While Loop | Do-While | Patterns | Numbers | Advanced Loops
| Mixed

Basic Output & Variables


Q1. Write a Java program to print your name, class, and school on separate lines.
Hint: Use [Link]() for each line.

Q2. Write a program to declare two integer variables, assign values 25 and 40, and print their sum,
difference, product, and quotient.
Hint: Use variables a=25, b=40 and arithmetic operators +, -, *, /.

Q3. Write a program to swap two numbers WITHOUT using a third variable. Use a=15, b=30.
Hint: Use arithmetic: a = a + b; b = a - b; a = a - b;

Q4. Write a program to calculate the area and perimeter of a rectangle with length=12 and
breadth=7.
Hint: Area = length * breadth. Perimeter = 2 * (length + breadth).
Q5. Write a program to find the remainder when 157 is divided by 13, and also check if it is
perfectly divisible.
Hint: Use % operator. If 157 % 13 == 0 then perfectly divisible.

If-Else-If
Q6. Write a program to check whether a given number is positive, negative, or zero. Test with n = -
9.
Hint: Use if(n>0), else if(n<0), else for zero.

Q7. Write a program to find the largest of THREE numbers using if-else-if. Test with a=34, b=78,
c=56.
Hint: Check all three combinations using && operator.

Q8. Write a program to assign grade based on marks:


90-100=A+, 80-89=A, 70-79=B, 60-69=C, 50-59=D, below 50=Fail.
Test with marks = 73.
Hint: Use if-else-if ladder from highest to lowest range.
Q9. Write a program to check whether a year is a LEAP YEAR or not. Test with year = 2024.
Rules: divisible by 4, but century years must be divisible by 400.
Hint: (year%4==0 && year%100!=0) || (year%400==0)

Q10. A student scores marks in 5 subjects. Write a program to find the total, average, and whether
the student passed (average >= 35) or failed.
Hint: Sum all marks, divide by 5 for average, compare average with 35.

Q11. Write a program using if-else-if to print the type of triangle based on sides:
All sides equal = Equilateral, Two sides equal = Isosceles, All different = Scalene.
Test with a=5, b=5, c=8.
Hint: Compare all three sides using == operator.

Q12. Write a program to check if a number is divisible by BOTH 3 and 5, only by 3, only by 5, or by
neither. Test with n = 15.
Hint: Use && for both, individual % checks for each.

Switch-Case
Q13. Write a program using switch-case to print the name of a month based on its number (1–12).
Test with month = 8.
Hint: Each case from 1 to 12 should print the corresponding month name.
Q14. Write a switch-case program to perform a simple calculator: add, subtract, multiply, divide
based on operator character. Test with a=20, b=4, op='/'.
Hint: Use char op = '/'; and switch on op with cases '+', '-', '*', '/'.

Q15. Write a program using switch-case to print the number of days in a month. Account for
months with 28, 30, and 31 days. Test with month = 2.
Hint: Group months with same days together using fall-through.

Q16. Write a switch-case program to print the season based on month number:
Dec,Jan,Feb = Winter | Mar,Apr,May = Spring | Jun,Jul,Aug = Summer | Sep,Oct,Nov = Autumn.
Test with month = 6.
Hint: Group months for each season using fall-through cases.

Q17. Write a program using switch-case to print whether a character is a Vowel or Consonant. Test
with ch = 'E'.
Hint: Switch on ch with cases 'a','e','i','o','u' and same for uppercase.
For Loop
Q18. Write a program using a for loop to print multiplication table of a given number. Test with n =
7.
Hint: Loop from 1 to 10, printing n * i each time.

Q19. Write a program to print all even numbers between 1 and 50 using a for loop, and also print
their count and sum.
Hint: Check i%2==0 inside the loop. Maintain count and sum variables.

Q20. Write a program to find the factorial of a number using a for loop. Test with n = 6.
Hint: Initialize fact=1, multiply fact by each i from 1 to n.

Q21. Write a program to print the Fibonacci series up to 10 terms using a for loop.
Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Hint: Start with a=0, b=1. Each term = a+b. Then shift: a=b, b=next.

Q22. Write a program to check if a number is PRIME using a for loop. Test with n = 29.
Hint: Count divisors from 2 to n-1. If count=0, it is prime.
Q23. Write a program to print all prime numbers between 1 and 50 using nested for loops.
Hint: Outer loop: 2 to 50. Inner loop: check divisors. If none found, print it.

While Loop
Q24. Write a program using a while loop to find the sum of digits of a number. Test with n = 4567.
Hint: Extract last digit using n%10, add to sum, then n=n/10. Repeat until n=0.

Q25. Write a program to reverse a number using a while loop. Test with n = 9876.
Hint: Extract digits using %10, build reversed number by *10+digit.

Q26. Write a program to check whether a number is a PALINDROME using a while loop. Test with n
= 1221.
Hint: Reverse the number and compare with original. If same, it is palindrome.

Q27. Write a program to find the GCD (Greatest Common Divisor) of two numbers using a while
loop. Test with a=48, b=18.
Hint: Use Euclidean algorithm: while(b!=0) { temp=b; b=a%b; a=temp; } Answer is a.

Q28. Write a program to count the number of digits in a number using a while loop. Test with n =
987654.
Hint: Divide n by 10 repeatedly until n becomes 0. Count each step.

Do-While Loop
Q29. Write a program using a do-while loop to print numbers from 1 to 10 and also their sum.
Hint: Initialize i=1, print i, add to sum, increment i. Check condition i<=10 at end.

Q30. Write a program using a do-while loop to print the powers of 2 up to 1024 (2^0 to 2^10).
Hint: Start with power=1, multiply by 2 each iteration. Stop when power > 1024.

Q31. Write a program using a do-while loop to find LCM (Lowest Common Multiple) of two
numbers. Test with a=12, b=18.
Hint: Start from max(a,b), keep adding max until divisible by both a and b.
Nested Loops & Patterns
Q32. Write a program to print the following RIGHT TRIANGLE star pattern (5 rows):
*
**
***
****
*****
Hint: Outer loop for rows (1 to 5), inner loop prints stars equal to row number.

Q33. Write a program to print the following INVERTED triangle pattern (5 rows):
*****
****
***
**
*
Hint: Outer loop from 5 to 1, inner loop prints stars from 1 to i.

Q34. Write a program to print the following NUMBER pattern (4 rows):


1
12
123
1234
Hint: Outer loop for rows, inner loop prints j from 1 to i.

Q35. Write a program to print a PYRAMID pattern of stars (5 rows):


*
**
***
****
*****
Hint: For each row i: print (5-i) spaces, then print i stars.

Q36. Write a program to print a 4x4 MULTIPLICATION TABLE using nested loops.
Hint: Outer loop i from 1–4, inner loop j from 1–4. Print i*j with formatting.

Q37. Write a program to print the following DIAMOND pattern (5 rows):


*
**
***
**
*
Hint: Split into upper half (1 to 3 stars) and lower half (2 to 1 stars).

Number Programs
Q38. Write a program to check if a number is an ARMSTRONG number. Test with n = 153.
Armstrong: sum of cubes of digits equals the number itself.
Hint: Extract each digit, cube it, add to sum. Compare sum with original.
Q39. Write a program to print all Armstrong numbers between 1 and 500.
Hint: For each number, check if sum of cubes of digits equals the number.

Q40. Write a program to find the sum of all natural numbers from 1 to N and verify using formula
N*(N+1)/2. Test with N = 100.
Hint: Use a loop for sum. Also compute formula result. Both should match.

Q41. Write a program to find all factors (divisors) of a given number. Test with n = 36.
Hint: Loop from 1 to n, print i if n%i==0. Also count total factors.

Q42. Write a program to find the power of a number without using [Link](). Test with base=3,
exponent=5.
Hint: Multiply base by itself exponent times using a loop.

Q43. Write a program to check if a number is a PERFECT NUMBER. Test with n = 28.
Perfect number: sum of proper divisors equals the number (e.g., 28 = 1+2+4+7+14).
Hint: Sum all divisors from 1 to n-1 where n%i==0. Compare sum with n.
Break, Continue & Advanced Loops
Q44. Write a program to print numbers from 1 to 20 but SKIP multiples of 3 using continue, and
STOP when reaching a multiple of 17.
Hint: Use continue for multiples of 3, break for multiples of 17.

Q45. Write a program to find the first number greater than 100 that is divisible by both 7 and 11.
Hint: Use a while loop starting from 101. Check if n%7==0 && n%11==0. Break when found.

Q46. Write a program to print only ODD numbers from 1 to 30 using a for loop with continue
statement.
Hint: Use continue when i%2==0 to skip even numbers.

Q47. Write a program to find the SMALLEST prime number greater than a given number n. Test
with n = 50.
Hint: Start from n+1, keep checking if each number is prime until one is found.

Mixed Programs
Q48. Write a program to print the following pattern using numbers:
1
23
456
7 8 9 10
Hint: Use a counter variable that increments across both loops.

Q49. Write a program to find how many numbers between 1 and 200 are divisible by 3 OR 5 but
NOT both.
Hint: Check (n%3==0 || n%5==0) && !(n%3==0 && n%5==0). Count and print them.

Q50. Write a program that prints a summary of numbers from 1 to 50:


- Count of even numbers
- Count of odd numbers
- Count of prime numbers
- Sum of all numbers
Hint: Use a single loop, maintain 4 counters/sums. Check even, odd, prime for each.

Total: 50 Questions | Answers on Answer Sheet | All The Best!

You might also like