Mook1(part1)
Mook1(part1)
import java.util.Scanner;
int largest = a;
if (b > largest) {
largest = b;
} else if (c > largest) {
largest = c;
} else if (d > largest) {
largest = d;
}
import java.util.Scanner;
if (num > 0) {
System.out.println("The number is positive.");
} else if (num < 0) {
System.out.println("The number is negative.");
} else {
System.out.println("The number is zero.");
}
}
}
11. Create a Java program that takes a character as input and checks if it is a
vowel using a switch conditional statement.
import java.util.Scanner;
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
System.out.println("The character is a vowel.");
break;
default:
System.out.println("The character is not a vowel.");
}
}
}
12. Write a Java program that takes an age as input and determines if a person is a
child, teenager, adult, or senior.
import java.util.Scanner;
JVM (Java Virtual Machine): It is a part of the JRE that runs Java bytecode on any
device or operating system, providing platform independence.
14. Difference between for loop, while loop, and do-while loop:
For loop: The initialization, condition check, and update happen in a single line.
Used when the number of iterations is known beforehand.
While loop: The condition is checked before executing the loop. It might not
execute if the condition is false initially.
Do-while loop: Similar to the while loop but guarantees at least one execution of
the loop body before checking the condition.
Actual argument: These are the values passed to the method when calling it.
Rules:
18. What is a method? Write syntax of a method and describe each term:
Method: A block of code that performs a specific task.
Syntax:
returnType methodName(parameterList) {
// method body
}
ReturnType: Specifies the type of value returned by the method.
MethodName: The name of the method.
ParameterList: A list of parameters (optional).
Method Body: The code that defines the functionality of the method.
19. Write a Java program to print the sum, average, sum of even numbers, sum of odd
numbers of an array.