0% found this document useful (0 votes)
26 views

Java Assignment

This document provides instructions for an assignment on control statements in Java. It outlines 9 tasks to complete that involve writing Java programs using different control statements like if-else statements, switch statements, for loops, while loops, do-while loops, nested loops, break and continue statements, enhanced for loops, and labeled loops. The tasks range from basic programs to print patterns and calculate sums, to more complex programs involving prime number checks and random number generation. Students are asked to write a separate Java program for each task, include comments, compile and run each program, and submit all files in a single zip file.

Uploaded by

shubhamshedge8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Java Assignment

This document provides instructions for an assignment on control statements in Java. It outlines 9 tasks to complete that involve writing Java programs using different control statements like if-else statements, switch statements, for loops, while loops, do-while loops, nested loops, break and continue statements, enhanced for loops, and labeled loops. The tasks range from basic programs to print patterns and calculate sums, to more complex programs involving prime number checks and random number generation. Students are asked to write a separate Java program for each task, include comments, compile and run each program, and submit all files in a single zip file.

Uploaded by

shubhamshedge8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment: Control Statements in Java

Instructions :For this assignment, you will explore various control statements in Java. Complete
the following tasks to demonstrate your understanding of control statements.

Task 1: If-Else Statements


1. Write a Java program that takes an integer input and checks if it's positive, negative, or zero.
Display the result accordingly.

Task 2: Switch Statement


1. Write a Java program that takes a month number (1 to 12) as input and displays the
corresponding month name using a switch statement.

Task 3: For Loop


1. Write a Java program to print the numbers from 1 to 10 using a for loop.
2. Modify the program to calculate the sum of all numbers from 1 to 10 and display the result.

Task 4: While Loop


1. Write a Java program that prompts the user to enter a positive integer. Use a while loop to
calculate the factorial of the input number and display the result.

Task 5: Do-While Loop


1. Write a Java program that generates random numbers from 1 to 100 until the number 50 is
generated using a do-while loop. Display the count of iterations needed to reach 50.

Task 6: Nested Loops


1. Write a Java program to print the following pattern using nested loops:
```
1
12
123
1234
12345
```

Task 7: Break and Continue


1. Write a Java program that takes a positive integer input and checks if it's a prime number using
a break statement. Display the result accordingly.
2. Write a Java program that uses a continue statement to print all even numbers from 1 to 20
except the number 10.

Task 8: Enhanced For Loop (ForEach)


1. Write a Java program that initializes an array of integers with values {1, 2, 3, 4, 5} and
calculates the sum of all elements using an enhanced for loop (forEach).
Task 9: Using Labels
1. Write a Java program to implement a nested loop labeled "outer" and "inner." Display the
output to demonstrate the labeled loop's behavior.

Submission Guidelines:
1. Write a Java program for each task and save them with appropriate filenames (e.g., Task1.java,
Task2.java, etc.).
2. Include comments to explain the purpose of each control statement in the program.
3. Compile and run each program to verify correctness and functionality.
4. Zip all the Java files into a single zip file and upload it on group

Good luck with your assignment on control statements in Java! Happy coding! 🚀

You might also like