Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views5 pages

String Array Programs 2

Uploaded by

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

String Array Programs 2

Uploaded by

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

STRING ARRAY PROGRAMS

import java.util.*;
class PROGRAM1
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
// sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
char ch=a[i].charAt(0);
if(ch=='A'||ch=='a')
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM2
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
char ch=a[i].charAt(0);
char chr=a[i].charAt(a[i].length()-1);
if((ch=='A'||ch=='a')&&(chr=='A'||chr=='a'))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM3
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
if(a[i].length()%2==0)
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM4
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
char ch=a[i].charAt(0);
char chr=a[i].charAt(a[i].length()-1);
if(ch==chr)
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM5
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
String s=a[i].substring(0,3);
if(s.equals("SRI"))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM6
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
if(a[i].startsWith("SRI"))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM7
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
if((a[i].startsWith("A") ||a[i].startsWith("a")) && (a[i].endsWith("A") ||
a[i].endsWith("a")))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM8
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
String s=a[i];
String rev="";
for(int j=0;j<s.length();j++)
{
char ch=s.charAt(j);
rev=ch+rev;
}
if(rev.equals(s))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM9
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
System.out.println("The output is ::");
for(int i=0;i<n;i++)
{
char ch=a[i].charAt(0);
char chr=a[i].charAt(a[i].length()-1);
if(Character.isUpperCase(ch) && Character.isUpperCase(chr))
System.out.println(a[i]);
}
}
}
import java.util.*;
class PROGRAM10
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of the array...");
int n=sc.nextInt();
sc.nextLine();
String a[]=new String[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
int c=0;
for(int i=0;i<n;i++)
{
char ch=a[i].charAt(0);
if("AEIOUaeiou".indexOf(ch)!=-1)
c++;
}
System.out.println("Number of words that begin with a vowel are ::"+c);
}
}

You might also like