Please select a subject first
Advertisements
Advertisements
Rewrite the following using ternary operator:
if (x%2 == o)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);
Concept: Introduction of Operators in Java
Write the return data type of the following function:
endsWith( )
Concept: String Functions
Write a Java expression for the following :
`sqrt(3"x"+"x"^2)/"a+b"`
Concept: Introduction of Operators in Java
What is the function of catch block in exception handling? Where does it appear in a program?
Concept: StringBuffer Functions
State the output when the following program segment is executed:
String a = "Smartphone", b = "Graphic Art";
String h = a.substring(2, 5);
String k = b.substring(S).toUpperCase();
System.out.println(h);
System.out.println(k.equalsignoreCase(h)); Concept: StringBuffer Functions
Write the output for the following :
System.out.printIn(“Incredible” + “\n” + “world”);
Concept: StringBuffer Functions
Give the output of the following string functions:
- “ACHIEVEMENT”.replace(E’, ‘A’)
- “DEDICATE”.compareTo(“DEVOTE”)
Concept: Concept of String Class
If int y = 10 then find int z = (++y * (y++ +5));
Concept: StringBuffer Functions
Rewrite the following using ternary operator :
if (bill > 10000)
discount = bill * 10.0 / 100;
else
discount = bill * 5.0 / 100;Concept: Introduction of Operators in Java
Design a class Railway Ticket with following description:
Instance variables/data members:
String name: To store the name of the customer
String coach: To store the type of coach customer wants to travel
long mob no: To store customer’s mobile number
int amt: To store a basic amount of ticket
int total amt: To store the amount to be paid after updating the original amount
Member methods
void accept (): To take input for a name, coach, mobile number and amount
void update (): To update the amount as per the coach selected
(extra amount to be added in the amount as follows)
| Type of Coaches | Amount |
| First_ AC | 700 |
| Second_AC | 500 |
| Third _AC | 250 |
| sleeper | None |
void display(): To display all details of a customer such as a name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods.
Concept: Concept of String Class
Special words are those words that start and end with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to accept a word check and print Whether the word is a palindrome or only a special word.
Concept: Concept of String Class
Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string.
Sample input: we are in a cyber world
Sample output: We Are In Cyber World
Concept: Introduction of Operators in Java
Write a program to input and store roll numbers, names and marks in 3 subjects of n number students in five single dimensional array and display the remark based on average marks as given below : (The maximum marks in the subject are 100).
Average marks = `"Total marks"/3`
| Average marks | Remark |
| 85 - 100 | Excellent |
| 75 - 84 | Distinction |
| 60 - 74 | First-class |
| 40 - 59 | Pass |
| Less than 40 | Poor |
Concept: Introduction of Operators in Java
Design a class to overload a function Joystring( )as follows:
(i) void Joystring (String s, char ch1 char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.
Example:
Input value of s = “TECHNALAGY”
ch1=‘A’,
ch2=‘O’
Output: TECHNOLOGY
(ii) void Joystring (String s) with one string argument that prints the position of the first space and the last space of the given string s.
Example:
Input value of = “Cloud computing means Internet based computing”
Output: First index: 5
Last index: 36
(iii) void Joystring (String s1, String s2) with two string arguments that combines the two string with a space between them and prints the resultant string. Example :
Input value of s1 =“COMMON WEALTH”
Input value of s2 =“GAMES”
Output: COMMON WEALTH GAMES
(use library functions)
Concept: StringBuffer Functions
Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for the name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”.
Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example —
Country Name: INDIA Output: INDIA-TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Concept: String Functions
Name the primitive data type in Java that is:
A 64-bit integer and is used when you need a range of values wider than those provided by int.
Concept: Introduction of Operators in Java
Name the primitive data type in Java that is :
A single 16-bit Unicode character whose default value is ‘\u0000’.
Concept: Introduction of Operators in Java
Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.
- &&
- %
- >=
- ++
Concept: Introduction of Operators in Java
State the output of the following program segment:
String str1 = “great”; String str2 = “minds”;
System.out.println (str1.substring (0,2).concat(str2.substring (1)));
System.out.println ((“WH”+(str1.substring (2).toUpperCase())));
Concept: StringBuffer Functions
Rewrite the following program segment using if-else statements instead of the ternary operator:
String grade = (mark >= 90) ? “A” : (mark >= 80) ? “B” : “C”;
Concept: StringBuffer Functions
