You are on page 1of 5

//3.

1
package com.mphasis.training.lab3;
import java.util.Scanner;

public class StringOperation3a {


public static void main (String[] args) {

Scanner s= new Scanner(System.in);


System.out.println("Please enter the string");
String a = s.next();
int l=a.length();
String ans="";
System.out.println("Select your choice of operation\r\n" +
"Options are\r\n" +
"1.Add the String to itself\r\n" +
"\r\n" +
"2.Replace odd positions with #\r\n" +
"\r\n" +
"3.Remove duplicate characters in the String\r\n" +
"\r\n" +
"4.Change odd characters to upper case\r\n");
int n= s.nextInt();

switch(n) {
case 1: ans=a+a;
break;

case 2:
for(int i=0;i<l;i++) {
if(i%2==0) {ans=ans+a.charAt(i);}
else {ans=ans+"#";}
}
break;

case 3:
int y=0;
for(int i=0;i<l;i++) {
for(int j=i-l;j<l;j--) {
if(j<0) {break;}
else {if(a.charAt(i)==a.charAt(j))
y++;}
}
if(y==0) {
ans=ans+a.charAt(i);
}
else if(y>0)
{
y=0;
}
}
break;

case 4:
for(int i=0;i<l;i++) {
if(i%2==0) {ans=ans+a.charAt(i);}
else
{ans=ans+Character.toUpperCase(a.charAt(i));}
}
break;
default:System.exit(0);
}
System.out.println("the output is"+ans);

___________________________________________________________________________________
___________________________________________________________________________________
_____
//3.2
package com.mphasis.training.lab3;

import java.util.Scanner;

public class PositiveString3b {


public static void main(String[] args) {
Scanner s= new Scanner(System.in);
System.out.println("Please enter the string");
String input = s.next();

int l=input.length();
int flag=0;
char [] c= input.toCharArray();
for(int i=0;i<l;i++)
{
for(int j=1;j<(l-i);j++)
{
if(c[j-1] > c[j])
{
flag=1;
}
}
}
if(flag==0)
System.out.println("The string is positive");
else
System.out.println("The string is negative");
}

___________________________________________________________________________________
___________________________________________________________________________________
______
//3.3
package com.mphasis.training.lab3;

import java.util.Date;
import java.text.*;

//Duration between CustomDate


public class DurationTodayDate3c {

public static void main(String[] args) {


String Startdate = "20/07/21 09:29:58";
String Stopdate = "20/07/22 09:33:43";

SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");

Date d1 = null;
Date d2 = null;

try {
d1 = format.parse(Startdate);
d2 = format.parse(Stopdate);
System.out.println(d1);
System.out.println(d2 + "\n");
} catch (ParseException e) {
e.printStackTrace();
}

long diff = d2.getTime() - d1.getTime();

int diffDays = (int) (diff / (24 * 60 * 60 * 1000));


long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000);

System.out.println("difference between days: " + diffDays+"Days.");


System.out.println("difference between seconds: " + diffSeconds + "
seconds.");
System.out.println("difference between minutues: " + diffMinutes + "
minutes.");
System.out.println("difference between hours: " + diffHours + " hours.");
System.out.println("difference between milliseconds: " + diff+
"milliseconds");

___________________________________________________________________________________
___________________________________________________________________________________
_________________________________________
//3.4
package com.mphasis.training.lab3;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class DurationLocalDates3d {

public static void main(String[] args)


{
Scanner s = new Scanner(System.in);
System.out.println("Enter the dates start and date in (yyyy-MM-dd)");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-
dd");

LocalDate n1= LocalDate.parse(s.nextLine(),formatter);


LocalDate n2= LocalDate.parse(s.nextLine(),formatter);
Period bet=Period.between(n1, n2);
int days=bet.getDays();
int months=bet.getMonths();
int years= bet.getYears();
System.out.println( "Days "+days+"\nMonths "+months+" \nYears"+years);
s.close();

}
}
___________________________________________________________________________________
___________________________________________________________________________________
______
//3.5
package com.mphasis.training.lab3;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class WarrenteeDate3e {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("Enter the purchase date in (yyyy-MM-dd)");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-
dd");
LocalDate n1= LocalDate.parse(s.nextLine(),formatter);
System.out.println("Enter the warranty year");
int year=s.nextInt();
System.out.println("Enter the warranty months");
int months=s.nextInt();
int days=(year*365)+(months*30);
LocalDate expiry= n1.plusDays(days);
System.out.println(expiry);

}
___________________________________________________________________________________
___________________________________________________________________________________
_________________________________________________
//3.6
package com.mphasis.training.lab3;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Scanner;

public class AcceptZone3f {


// TODO Auto-generated method stub
public static void main(String[] args) {
ZoneId zoneid1 = ZoneId.of("Asia/Kolkata");
ZoneId zoneid2 = ZoneId.of("Asia/Tokyo");
LocalTime id1 = LocalTime.now(zoneid1);
LocalTime id2 = LocalTime.now(zoneid2);
System.out.println(id1);
System.out.println(id2);
System.out.println(id1.isBefore(id2));
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________________________________
//3.7
package com.mphasis.training.lab3;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
import com.mphasis.training.lab2.Person;

public class Person3g {

public void calculateAge(LocalDate dob) {


LocalDate n2= LocalDate.now();
Period bet=Period.between(dob, n2);
int years= bet.getYears();
System.out.println( "your age is : "+years);
}

public void getFullName(String fname,String lname) {


String fullname=fname+" "+lname;
System.out.println( "your fullname is : "+fullname);
}

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);


Person p= new Person("Divya","Bharathi",'F',22,85.55);
System.out.println(p.PrintPersonDetails());

System.out.println("Enter dob in (yyyy-MM-dd)");


DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-
MM-dd");
LocalDate dob= LocalDate.parse(sc.nextLine(),formatter);
Person3g p1 = new Person3g();
p1.calculateAge(dob);
p1.getFullName(p.FirstName,p.LastName);

}
}

You might also like