Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

java conditional

The document contains multiple Java programs that validate various inputs, including date formats, time formats, and geometric properties. Each program reads input from the user and checks for validity, such as confirming if a date is valid, if a time is within a specified range, or determining the maximum and minimum of given numbers. Additionally, it includes checks for triangle types based on side lengths and angle sums.

Uploaded by

Pradisha P
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java conditional

The document contains multiple Java programs that validate various inputs, including date formats, time formats, and geometric properties. Each program reads input from the user and checks for validity, such as confirming if a date is valid, if a time is within a specified range, or determining the maximum and minimum of given numbers. Additionally, it includes checks for triangle types based on side lengths and angle sums.

Uploaded by

Pradisha P
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

import java.util.

Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
String[] parts = input.split("/");
if (parts.length != 3) {
System.out.println("Invalid date format");
return;
}
int date = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]);
if (isValidDate(date, month, year)) {
System.out.println("Valid");
} else {
System.out.println("Invalid");
}
}
public static boolean isValidDate(int date, int month, int year) {
if (date > 0 && date < 32 && month > 0 && month < 13 && year > 0 && year <
10000) {
if (date < 31 && (month == 4 || month == 6 || month == 9 || month ==
11)) {
return true;
} else if (date < 32 && (month == 1 || month == 3 || month == 5 ||
month == 7 || month == 8 || month == 10 || month == 12)) {
return true;
} else if (month == 2) {
if ((date < 30 && ((year % 4 == 0 && year % 100 != 0) || (year %
400 == 0))) || (date < 29)) {
return true;
}
}
}
return false;
}
}

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
sdf.setLenient(false);
try {
Date date = sdf.parse(input);
int hours = Integer.parseInt(input.split(":")[0]);
if (hours >= 0 && hours <= 24) {
System.out.println("Valid");
} else {
System.out.println("Not Valid");
}
} catch (ParseException | NumberFormatException e) {
System.out.println("Not Valid");
}
}
}

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long n1 = scanner.nextLong();
long n2 = scanner.nextLong();
long n3 = scanner.nextLong();
long n4 = scanner.nextLong();
long max1 = Math.max(Math.max(n1, n2), Math.max(n3, n4));
long min1 = Math.min(Math.min(n1, n2), Math.min(n3, n4));
long min2 = Math.min(Math.max(n1, n2), Math.max(n3, n4));
long max2 = Math.max(Math.min(n1, n2), Math.min(n3, n4));
if (max2 < min2) {
long temp = max2;
max2 = min2;
min2 = temp;
}
System.out.printf("%d > %d > %d > %d", max1, max2, min2, min1);
}
}

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long num1 = scanner.nextLong();
long num2 = scanner.nextLong();
long num3 = scanner.nextLong();
long max = Math.max(Math.max(num1, num2), num3);
long min = Math.min(Math.min(num1, num2), num3);
long mid = num1 + num2 + num3 - max - min;
System.out.printf("%d < %d < %d", min, mid, max);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long n1 = scanner.nextLong();
long n2 = scanner.nextLong();
long n3 = scanner.nextLong();
long n4 = scanner.nextLong();
long max = (n1 > n2 ? n1 : n2) > (n3 > n4 ? n3 : n4) ? (n1 > n2 ? n1 :
n2) : (n3 > n4 ? n3 : n4);

System.out.printf("Largest is %d", max);


}
}

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long num1 = scanner.nextLong();
long num2 = scanner.nextLong();
long num3 = scanner.nextLong();
if (num1 > num2 && num1 > num3) {
System.out.printf("Maximum is %d", num1);
} else if (num2 > num1 && num2 > num3) {
System.out.printf("Maximum is %d", num2);
} else {
System.out.printf("Maximum is %d", num3);
}
}
}

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long num1 = scanner.nextLong();
long num2 = scanner.nextLong();
long num3 = scanner.nextLong();

if (num1 < num2 && num1 < num3) {


System.out.printf("Minimum is %d", num1);
} else if (num2 < num1 && num2 < num3) {
System.out.printf("Minimum is %d", num2);
} else {
System.out.printf("Minimum is %d", num3);
}
}
}

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int angle1 = scanner.nextInt();
int angle2 = scanner.nextInt();
int angle3 = scanner.nextInt();

if ((angle1 + angle2 + angle3 == 180) && angle1 != 0 && angle2 != 0 &&


angle3 != 0) {
System.out.println("Valid");
} else {
System.out.println("Not Valid");
}
}
}

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int side1 = scanner.nextInt();
int side2 = scanner.nextInt();
int side3 = scanner.nextInt();

if (side1 == side2 && side2 == side3) {


System.out.println("Equilateral");
} else if (side1 == side2 || side2 == side3 || side3 == side1) {
System.out.println("Isosceles");
} else {
System.out.println("Scalene");
}
}
}

You might also like