Advertisements
Advertisements
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
Give the output of the following method:
public static void main (String [] args)
{
int a = 5;
a++;
System.out.println(a);
a -= (a--) − (--a);
System.out.println(a);
}
Concept: StringBuffer Functions
State the value of characteristic and mantissa when the following code is executed:
String s = “4.3756”;
int n = s.indexOf(‘.’);
int characteristic=Integer.parseInt (s.substring (0,n));
int mantissa=Integer.valueOf(s.substring(n+1));
Concept: StringBuffer Functions
Define a class named movieMagic with the following description:
Instance variables/data members:
int year — to store the year of release of a movie.
String title — to-store the title of the movie
float rating — to store the popularity rating of the movie
(minimum rating=0.0 and maximum rating=5.0)
Member methods:
(i) movieMagic() Default constructor to initialize numeric data members to 0 and String data member to “ ”.
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as per the table below.
| Rating | Message to be displayed |
| 0.0 to 2.0 | Flop |
| 2.1 to 3.4 | Semi-hit |
| 3.5 to 4.5 | Hit |
| 4.6 to 5.0 | Super Hit |
Write a main method to create an object of the class and call the above member methods.
Concept: StringBuffer Functions
Give the output of the following string methods.
"MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
Concept: String Functions
Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.
Concept: String Functions
