DEV Community

Ramya K
Ramya K

Posted on

1 1 1

Java Program

1.Displaying vowels from the string
`package com.practise;

import java.util.Scanner;

public class PrintVowels {

public static void main(String[] args) {
    Scanner scanner=new Scanner(System.in);
System.out.println("Enter the name to display only vowels");
String name=scanner.next();

for(int i=0;i<name.length();i++) {
    if(name.charAt(i)=='A'||name.charAt(i)=='a'||name.charAt(i)=='E'||name.charAt(i)=='e'
            ||name.charAt(i)=='I'||name.charAt(i)=='i'||name.charAt(i)=='O'||name.charAt(i)=='o'
            ||name.charAt(i)=='U'||name.charAt(i)=='u') {
        System.out.print(name.charAt(i));
    }
}
}
Enter fullscreen mode Exit fullscreen mode

}`

Output:
Enter the name to display only vowels
Toddayismonday
oaioa

  1. Finding the mobile number from String `package com.first;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FindMobileNumber {

public static void main(String[] args) {
String input="My mobile number is 9234561789";
Pattern pattern=Pattern.compile("[0-9]");
Matcher matcher=pattern.matcher(input);
while(matcher.find()) {
    System.out.print(matcher.group());

}
}
Enter fullscreen mode Exit fullscreen mode

}`

output:
9234561789

3.Finding mobile number from file
`package com.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FindMobilenumberfromFile {
public static void main(String[] args) throws IOException {
File folder=new File("C:/Users/OneDrive/Documents/Test");
folder.mkdir();
File note=new File("C:/Users/OneDrive/Documents/Test/test.txt");
note.createNewFile();
FileWriter pen = new FileWriter(note);

pen.write("A picture word essay refers to an essay that utilizes a combination of "
+ "images 68768 and written words to convey a message or tell a story. "
+ "It's a form of visual storytelling, where the pictures and the words "
+ "9879345634 work together to create a cohesive narrative.");
pen.close();

BufferedReader reader=new BufferedReader(new FileReader("C:/Users/"
+ "OneDrive/Documents/Test/test.txt"));

Pattern pattern=Pattern.compile("[6-9][0-9]{9}");
String input=reader.readLine();
    while(input!=null) {                            
        Matcher matcher=pattern.matcher(input);
        while(matcher.find()) {
            System.out.print(matcher.group());              
        }           
        input=reader.readLine();
        System.out.println(" ");        }
    reader.close();
} }
Enter fullscreen mode Exit fullscreen mode

`

output:
9879345634

Google AI Education track image

Build Apps with Google AI Studio 🧱

This track will guide you through Google AI Studio's new "Build apps with Gemini" feature, where you can turn a simple text prompt into a fully functional, deployed web application in minutes.

Read more →

Top comments (0)

Google AI Education track image

Work through these 3 parts to earn the exclusive Google AI Studio Builder badge!

This track will guide you through Google AI Studio's new "Build apps with Gemini" feature, where you can turn a simple text prompt into a fully functional, deployed web application in minutes.

Read more →

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay