alis
BAN USER- 0of 0 votes
AnswersString d1="7 dec 2012";
- alis in India
String d2="15 dec 2012";
String d3="12 dec 2012";
String d4="16 dec 2012";
String d5="16 dec 2012";
String d6="24 dec 2012";
days between d1 and d2 is: 9
days between d3 and d4 is: 1 (12 dec to 15 dec counted in d1 and d2, don't count overlapping days)
days between d3 and d4 is: 8 (16 dec counted in d3 and d4, don't count overlapping days)
now final output should be: 9 + 1 + 8=18| Report Duplicate | Flag | PURGE
Tricon Java Developer Java
package com.dev;
public class P3_FindOccuranceOfSubStringInStringWithOutIUsingFun {
public static void main(String[] args) {
String str = "cdcde";
String input = "cde";
// cdcde, abcdefghcgde
String flag = "";
char[] strChar = str.toCharArray();
char[] inputChar = input.toCharArray();
int count = 0;
int i = 0, j = 0;
int numberOfInputs = 0;
while (count <= strChar.length - 1) {
// if (strChar[i] == inputChar[j]) {
int k = count;
j = 0;
while (j <= inputChar.length - 1) {
if (strChar[k] == inputChar[j]) {
flag = "found";
} else {
flag = "not found";
break;
}
k++;
j++;
}
if (flag.equalsIgnoreCase("found")) {
numberOfInputs++;
}
count++;
}
System.out.println("numberOfInputs : " + numberOfInputs);
}
}
public class P3_FindOccuranceOfSubStringInStringWithOutIUsingFun {
public static void main(String[] args) {
String str = "cdcde";
String input = "cde";
// cdcde, abcdefghcgde
String flag = "";
char[] strChar = str.toCharArray();
char[] inputChar = input.toCharArray();
int count = 0;
int i = 0, j = 0;
int numberOfInputs = 0;
while (count <= strChar.length - 1) {
// if (strChar[i] == inputChar[j]) {
int k = count;
j = 0;
while (j <= inputChar.length - 1) {
if (strChar[k] == inputChar[j]) {
flag = "found";
} else {
flag = "not found";
break;
}
k++;
j++;
}
if (flag.equalsIgnoreCase("found")) {
numberOfInputs++;
}
count++;
}
System.out.println("numberOfInputs : " + numberOfInputs);
}
}
package com.lara5;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestJava {
public static int daysBetween(Date d1, Date d2)
{
/*This function returns the difference in days given 2 dates as input*/
int days=(int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
return days;
}
public static void main(String args[]) throws ParseException
{
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
Date date = sdf.parse("07122012"); // Date1
cal1.setTime(date);
date = sdf.parse("15122012"); // Date2
cal2.setTime(date);
int daysBetween = daysBetween(cal1.getTime(),cal2.getTime()); // Days between Date1 and Date2
int interval = daysBetween(cal1.getTime(),cal2.getTime());
System.out.println("Interval1 == "+ interval);
date = sdf.parse("12122012"); // Date3
cal1.setTime(date);
date = sdf.parse("16122012"); // Date4
cal2.setTime(date);
daysBetween += daysBetween(cal1.getTime(),cal2.getTime()); // Days between Date3 and Date4 is added to the previously available value of days between Date1 and Date2
interval = daysBetween(cal1.getTime(),cal2.getTime());
System.out.println("Interval2 == "+ interval);
date = sdf.parse("16122012");
cal1.setTime(date);
date = sdf.parse("24122012");
cal2.setTime(date);
daysBetween += daysBetween(cal1.getTime(),cal2.getTime()); // Total required difference as per the question
interval = daysBetween(cal1.getTime(),cal2.getTime());
System.out.println("Interval3 == "+ interval);
System.out.println("Total Interval == "+ daysBetween);
}
}
package com.dev;
- alis January 26, 2016public class P7_NumberOfTwoTillInput {
public static void main(String[] args) {
numberOfTwo("13");
}
private static void numberOfTwo(String input) {
int count = 0;
char[] tmpArray = null;
for (Integer i = 0; i < Integer.parseInt(input); i++) {
if (String.valueOf(i).contains("2")) {
if (String.valueOf(i).length() == 1) {
count++;
} else {
tmpArray = String.valueOf(i).toCharArray();
for (int j = 0; j < tmpArray.length; j++) {
if (tmpArray[j] == '2') {
count++;
}
}
}
}
}
System.out.println(count);
}
}