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

Assignment Answer

The document contains two programming assignments by Payal Dharma Mehta, focusing on expression evaluation and control structures in Java. The first assignment demonstrates basic arithmetic operations, while the second showcases the use of if statements, switch statements, and various loop constructs. Both assignments illustrate fundamental programming concepts and syntax in Java.

Uploaded by

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

Assignment Answer

The document contains two programming assignments by Payal Dharma Mehta, focusing on expression evaluation and control structures in Java. The first assignment demonstrates basic arithmetic operations, while the second showcases the use of if statements, switch statements, and various loop constructs. Both assignments illustrate fundamental programming concepts and syntax in Java.

Uploaded by

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

Assignment No.

Problem Statement: Write programs to evaluate different types of expressions.


Name: Payal Dharma Mehta
Roll No: 2319

public class ExpressionEvaluation {


public static void main(String[] args) {
int a = 10, b = 20;
System.out.println("Addition: " + (a + b));
System.out.println("Subtraction: " + (a - b));
System.out.println("Multiplication: " + (a * b));
System.out.println("Division: " + (a / b));
System.out.println("Modulus: " + (a % b));
}
}

Assignment No. 3

Problem Statement: Develop a program to implement different control structures (if,


switch, loops - for, while, do while).
Name: Payal Dharma Mehta
Roll No: 2319

public class ControlStructures {


public static void main(String[] args) {
int num = 10;

// if statement
if (num > 0) {
System.out.println("Positive number");
}

// switch statement
switch (num) {
case 10:
System.out.println("Number is 10");
break;
default:
System.out.println("Number is not 10");
}

// for loop
for (int i = 1; i <= 5; i++) {
System.out.println("For loop iteration: " + i);
}

// while loop
int i = 1;
while (i <= 5) {
System.out.println("While loop iteration: " + i);
i++;
}

// do-while loop
int j = 1;
do {
System.out.println("Do-while loop iteration: " + j);
j++;
} while (j <= 5);
}
}

You might also like