## Posts

A program which will accept three sentences (one sentence per line) and print the words having Initial Caps within the sentences. Below is an example.

Here is an example. If the below three sentences are given to the program as input,

This is a Program
Coding test of Initial Caps
the program Will Test You

Then, the output would look like:

This
Program
Coding
Initial
Caps
Will
Test
You

Solution:
Pattern p = Pattern.compile("^[A-Z]");

Where 1999 is the year and 5 is the numeric sequence of the month (corresponding to June). The program should display the day on which June 28, 1999 fell, and in this case the output will be MONDAY.

The output should be displayed in uppercase letters.

Suppose the following INPUT sequence is given to the program:

1999-5
1998-6

Then the output should be:

MONDAY
TUESDAY

Solution:

import java.text.DateFormatSymbols; import java.util.Calendar; import java.util.Scanner; public class Solution { /** * @param args */ public static void main(String[] args) { boolean condition = false; do { Scanner scanner = new Scanner(System.in); String value = scanner.nextLine(); condition = value.equalsIgnoreCase("exit"); if(!condition && value.contains("-")){ calculate(value); } System.out.println("Count is: " + condition); } while (!condition); } private static void calculate(String value) { final String[] input = value.split(…

Write a program that prints the numbers between 258 and 393 (both inclusive) which do not end with 5. The program should print the output so as to have one value per line. The output would therefore follow the below format:

value1
value2
value3
.
..
.
so on
Solution:
public class Solution2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int start = 258; int end = 393; for (int i = start; i < end; i++) { if(i%10 !=5){ System.out.println(i); } } } }

A program which will accept a single pair of strings separated by a comma; the program should calculate the sum of ASCII values of the characters of each string. The program should then subtract the sum of the ASCII values of the second string from the sum of the ASCII values of the first string.

Suppose the following input is given to the program:

123ABC,456DEF

Then the sum of the ASCII values of the characters in '123ABC' is 348 and in '456DEF' it is 366. The Difference between these numbers is 348 – 366 = -18
The corresponding output to be printed by the program is:

-18

Solution:
import java.util.Scanner; public class Solution { /** * @param args */ public static void main(String[] args) { boolean condition = false; do { Scanner scanner = new Scanner(System.in); String value = scanner.nextLine(); condition = value.equalsIgnoreCase("exit"); if(!condition && value.contains(",")){ calculate(value); } } while …

### Google App Engine DataNucleus “does not seem to have been enhanced” Issue

I got DataNucleus exception while developing a Google App Engine based Web Application for one of my office clients. Here is the error message.

javax.jdo.JDOUserException: Persistent class "Class com.xxxxx.xxxxx.domain.XXXXXUser does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class. at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:375) at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:252) NestedThrowablesStackTrace:
Persistent class "Class com.xxxxx.xxxxx.domain.XXXXXUser does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it.Please check the specification of the MetaData for this class. org.datanucleus.store.exceptions…

### How to parse toString date value to Date object

I have some issue with toString date value parse to Date object. here is my solution for that.

try { Date cutterntTime = new Date(); String dateStringValue = cutterntTime.toString(); //String dateStringValue = Thu May 05 11:26:49 IST 2011; DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = (Date)formatter.parse(dateStringValue); System.out.println("Date Value is : " + date); } catch (ParseException e){ System.out.println("Exception :"+e); }

### How do I get dates between two dates?

In the following example code I am going to get  dates between two dates. First, I need to convert the date value into milliseconds and increase startup date value from one date.

One date in milliseconds equlas to 24 * 60 * 60 * 1000L

import java.util.*; public class DateUtil { static final long ONE_DAY = 24 * 60 * 60 * 1000L; public static void main(String[] args) { getDatesBetween("03/23/2011","03/28/2011"); } public static void getDatesBetween(String startDate,String endDate) { long from=Date.parse(startDate); // long value of from date long to=Date.parse(endDate); // long value of to date int x=0; while(from <= to) { x=x+1; System.out.println ("Dates : "+new Date(from)); from += ONE_DAY; } System.out.println ("No of Dates :"+ x); } }