0% found this document useful (0 votes)
3 views3 pages

Program Practice Set 1

The document outlines a practice set for programming in Java, covering various topics such as operator precedence, string manipulation, user-defined exceptions, and object-oriented programming concepts. It includes tasks like calculating factorials, managing vehicle types, and processing strings with specific operations. Additionally, it emphasizes the implementation of classes, inheritance, and method overriding in different scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Program Practice Set 1

The document outlines a practice set for programming in Java, covering various topics such as operator precedence, string manipulation, user-defined exceptions, and object-oriented programming concepts. It includes tasks like calculating factorials, managing vehicle types, and processing strings with specific operations. Additionally, it emphasizes the implementation of classes, inheritance, and method overriding in different scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM PRACTICE SET 1

1. Analyze the following line of code if executed :


a. System.out.println(50 + 70 + "BTech");
b. System.out.println("University" + 30 + 20);

2. class OperatorPrecedence {
public static void main(String args[])
{
int f = 2;
System.out.print((f++ * 8) - ((++f + --f) * f++));
} }
3. What will be the output of the following:
int a = 2;

int result = a++ * ++a * a++;

System.out.println("a: " + a);

System.out.println("result: " + result);

4. public class Question3 {


public static void main(String[] args) {
String b = "Hello";
String d = b.concat(" World");
System.out.println(b);
}
}
5. WAP to store the ages of 5 people. Throw a user-defined exception if the entered age is less
than 0 or more than 120.
6. WAP to do basic addition and subtraction using static methods.
7. WAP to calculate factorial of an integer with and without recursion .
8. Write a Java program to input a 3x3 matrix of integers, calculate its transpose, and replace all
even numbers with -1 in the transposed matrix.
9. Find the output

public class Question2 {


public static void main(String[] args) {
int a = 10;
int b = a++ + 3;
int c = ++b * 2;
System.out.println("a: " + a);
System.out.println("b: " + b);
System.out.println("c: " + c);
}
}
10. Write java codes to check whether a 123321 is palindrome or not.
11. Create a program to model different types of vehicles in a transportation system. There are
three types of vehicles: Cars, Bicycles, and Trains.
All vehicles have common properties such as brand and speed, and common behaviors such as
start() and stop().
Each type of vehicle has its own specific behavior:
 Cars honk
 Bicycles ringBell
 Trains whistle
12. WAP in java with a class called Person with attributes such as name and age. Then, create two
subclasses: Student and Teacher.
 Student should have an additional attribute grade.
 Teacher should have an additional attribute subject.
Implement methods to display the details of each person.**

13. WAP to manage different types of appliances in a smart home system. There are three types of
appliances: Fan, Light, and AirConditioner.
All appliances have a common behavior of displaying their status and power consumption.
However, each type of appliance has its own specific behavior:
a. Fans rotate
b. Lights illuminate
c. AirConditioners cool the room.
Implement classes for each and demonstrate the use of inheritance and method
overriding
14. WAP for a hierarchy of Electronic Devices using a base class Device with common methods like
turnOn(), turnOff(), and use(). Implement concrete subclasses such as Phone, Laptop, and
Tablet.
Each type of device should have its own specific behavior:
 Phones make calls.
 Laptops run software.
 Tablets display content.

15. We have Two one-dimensional arrays X and Y which are sorted in descending order, write a
program to merge them into a single sorted array Z that contains every item from arrays X and Y
in descending order.
16. Write a java program to generate all permutations of String FLAT.
Program:
17. Write a Java program to print a string in reverse order without using any pre-defined string
function. For eg print FLAT as TALF.
18. Write a Java program to calculate the length of the string and compare it with another different
string .
19. Write a Java program to create an abstract class named Solid that contains two integers and an
empty method named printVolume(). Overload the method printVolume() to calculate the
volume of:
 Cube
 Cuboid

20. Write a Java program to process the string "Programming is fun and powerful!".
Perform the following operations:
1. Convert the string to uppercase.
2. Replace the word "powerful" with "creative".
3. Split the sentence into words and display each word on a new line.
4. Reverse the entire string and print it.

You might also like