0% found this document useful (0 votes)
2 views

problemstatement

The document contains three Java programs that perform different tasks. The first program counts the number of vowels and consonants in a user-input string. The second program searches for a specified word within a user-input string, while the third program formats and displays a user-input date in a different format.

Uploaded by

Akash Padir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

problemstatement

The document contains three Java programs that perform different tasks. The first program counts the number of vowels and consonants in a user-input string. The second program searches for a specified word within a user-input string, while the third program formats and displays a user-input date in a different format.

Uploaded by

Akash Padir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();

int vowels = 0, consonants = 0;

for (char ch : input.toLowerCase().toCharArray()) {


if (Character.isLetter(ch)) { // Check if it's a letter
if ("aeiou".indexOf(ch) != -1) vowels++;
else consonants++;
}
}

System.out.println("Vowels: " + vowels);


System.out.println("Consonants: " + consonants);
}
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();
System.out.print("Enter the word to find: ");
String word = scanner.nextLine();

int index = input.indexOf(word);


System.out.println(index != -1 ? "Word found at index: " + index : "Word
not found.");
}
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {


public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a date (dd/MM/yyyy): ");
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(scanner.nextLine());
System.out.println(new SimpleDateFormat("dd MMM yyyy").format(date));
}
}

You might also like