01_ Coding: String reverse ............
String reverse
Method 1.
Method 2.
Method 3.
Method 4.
Print a to z
public static void main(String[] args) {
char c;
for (c = 'a'; c <= 'z'; c++) {
System.out.print(c + ", ");
}
}
Rendom num generation with bound
public static void main(String[] args) {
int min=4;
int max =10;
int num = (int)(Math.random()*(max-min-1)+min);
System.out.println("random usint Math.random method " +num);
Random rn = new Random();
int ny= rn.nextInt(max-min-1)+min;
System.out.println("random usint random Class " +ny);
}
Date and time formate
//Formatting Date/Time to String:
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter2);
System.out.println(formattedDateTime);
//Parsing String to Date/Time:
String dateTimeString = "02-03-2024 14:30:00";
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss");
LocalDateTime parsedDateTime = LocalDateTime.parse(dateTimeString, formatter3);
System.out.println(parsedDateTime);
Comments
Post a Comment