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

Rahul Java Programs

The document provides coding practice exercises and questions for an interview candidate to answer. It includes: 1) An exercise to count the number of occurrences of each day of the week in a month. 2) An explanation of why an AVG function cannot be used in a WHERE clause and how to fix the SQL query. 3) Ways to identify a user connecting to a web service, such as HTTP authentication or digital signatures. 4) An explanation of what HTTP status code 409 means with an example of trying to post a duplicate record. 5) Using vowel counts in words to determine the price of an unknown item. 6) Reasons manhole covers are round rather

Uploaded by

Priyanka mestry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Rahul Java Programs

The document provides coding practice exercises and questions for an interview candidate to answer. It includes: 1) An exercise to count the number of occurrences of each day of the week in a month. 2) An explanation of why an AVG function cannot be used in a WHERE clause and how to fix the SQL query. 3) Ways to identify a user connecting to a web service, such as HTTP authentication or digital signatures. 4) An explanation of what HTTP status code 409 means with an example of trying to post a duplicate record. 5) Using vowel counts in words to determine the price of an unknown item. 6) Reasons manhole covers are round rather

Uploaded by

Priyanka mestry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Coding Practice Exercise - 01

(Use Any programming Language which you comfortable, Post your answer to me separately)

1: Print HELLO for the given string "AHCECLWLXO"

2: Print HELLO in CAPITAL letters for the given string "ahceclwlxo"

Raj:

Coding Practice Exercise - 07

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1: Ask user to input starting day and the number of days in a month. Find the number of times every
day occurs in that month. Ex: Input : Number of days in month = 30 , First day = Tuesday

Output : Monday=4, Tuesday=5, Wednesday=5, Thursday=4, Friday=4, Saturday=4, Sunday=4;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import java.util.*;

import java.lang.*;

public class GfG{

// function to find occurrences

public static void occurrenceDays(int n, String firstday)

// stores days in a week

String[] days = new String[]{ "Monday",

"Tuesday", "Wednesday",

"Thursday", "Friday",

"Saturday", "Sunday" };

// Initialize all counts as 4.

int[] count = new int[7];


for (int i = 0; i < 7; i++)

count[i] = 4;

// find index of the first day

int pos = 0;

for (int i = 0; i < 7; i++)

if (firstday == days[i])

pos = i;

break;

// number of days whose occurrence

// will be 5

int inc = n - 28;

// mark the occurrence to be 5 of n-28 days

for (int i = pos; i < pos + inc; i++)

if (i > 6)

count[i % 7] = 5;

else

count[i] = 5;

// print the days

for (int i = 0; i < 7; i++)


{

System.out.println(days[i] + " " + count[i]);

// Driver function

public static void main(String argc[]){

int n = 31;

String firstday = "Tuesday";

occurrenceDays(n, firstday);

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2: What’s wrong in the following query?

SELECT subject_code, AVG (marks)

FROM students

WHERE AVG(marks) > 75

GROUP BY subject_code;

"AVG" is a type of "Multirows function (MRF)" and we cannot write MRF's in WHERE clause because
MRF's executes group-by-group and WHERE clause executes row-by-row. But we can write MRF's in
having clause. So the correct query would be

SELECT subject_code,AVG(marks)

FROM students

GROUP BY subject_code

HAVING AVG(marks)>75

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3: If a client connects to a web service, how do we identify the user?


HTTP includes built-in support for Basic and Digest authentication.SOAP Digital Signature (SOAP-DSIG)
leverages public key cryptography to digitally sign SOAP messages. It enables the client or server to
validate the identity of the other party.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

4: What HTTP Status Code 409 states in web-service, explain with example.

If there is a record exist in DB and we do post for that same record in that case server will return 409
error code

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

5: An apple costs 40 cents, a banana costs 60 cents, and a grapefruit costs 80 cents. How much does a
pear cost?

Apple-> 2 vowels -->40cents : Banana-->3 vowels-->60cents : Grapefruit-->4 vowels -->80cents :

So from above examples we can say that each vowel is equals to 20cents. So Pear --> 2 vowels-->
40cents. So answer is Pear costs 40cents.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

6: Why are manhole covers round and not square?

A: A manhole round can be rotate in any ways and it will not fall into it. So it is safer to use round than
square. Square will fall in to it

B: Manhole cover is round because we can transfer that cover from one place to another by simply
rotating the cover , so it more easier than any other shapes

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

7: Is it better to be perfect and late, or good and on time?

As a general rule, managers prefer “good and on time”, as they don’t appreciate work to stay pending
because of the employees’ need for perfection.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

8: Describe a bad experience you had working with your ex-employer

Never bad-mouth previous colleagues and ex-employees. Instead of focusing on the details of the
incident, put more emphasis on the part where you managed to make him see your point-of-view.

For example − “They were thinking from a different point of view, but in the end, they managed to
understand my concerns as well.”

You might also like