0% found this document useful (0 votes)
47 views11 pages

COMPUTER

The document contains 10 Java programs that perform various string manipulation tasks like counting words, letters, removing vowels, capitalizing initials, extracting surname and first name etc.

Uploaded by

gracevijoy
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)
47 views11 pages

COMPUTER

The document contains 10 Java programs that perform various string manipulation tasks like counting words, letters, removing vowels, capitalizing initials, extracting surname and first name etc.

Uploaded by

gracevijoy
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/ 11

COMPUTER

import java.util.*;
public class q
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("");
}
}

import java.util.*;
public class q1
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sen = in.nextLine();
String t = sen.trim();
String sr = t + " ";
int p = sr.length();
int w = 0, let = 0;
for (int i = 0; i < p; i++) {
char c = sr.charAt(i);
if (Character.isWhitespace(c))
w++;
if (Character.isLetter(c))
let++;
}
System.out.println("No. Of words=" + w);
System.out.println("No. of letters=" + let);
}
}

import java.util.*;
public class q2
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String");
String sen = in.nextLine();
String s = sen.trim();
int l = s.length();
String sr = "";
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if ("aeiouAEIOU".indexOf(c) == -1)
sr = sr + c;
}
System.out.println(sr);
}
}

import java.util.*;
public class q3
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a name with 3 words");
String name=in.nextLine();
String n=name.trim();
String na=" "+n;
int l=na.length();
for (int i=0;i<l;i++)
{
char c = na.charAt(i);
if (c==' ')
{
char ini=na.charAt(i+1);
System.out.print(Character.toUpperCase(ini)+" ");
}
}
}
}

import java.util.*;
public class q4
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a name of three words:");
String name=in.nextLine();
String n=name.trim();
int lastspace=n.lastIndexOf(' ');
String surn=n.substring(lastspace+1);
String fm=n.substring(0,lastspace);
System.out.println(surn+" "+fm);
}
}
import java.util.*;

public class q5
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String:");
String S = in.nextLine();
String s = S + ' ';
int l = s.length();
String Ls = "";
for (int i = 0; i < l; i++)
{
String w = "";
String o = "";
char c = s.charAt(i);
w = w + c;
if (c == ' ') {
o = w.trim();
if (o.length() > Ls.length())
Ls = o;
}
}
System.out.println("Longest Word: " + Ls);
System.out.println("Length of Longest word: " + Ls.length());
}
}
import java.util.*;
public class q6
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a word:");
String w=in.next();
String s=w.trim();
int l=s.length();
for (int i=0;i<l;i++)
{
char c=s.charAt(i);
System.out.println("ASCII CODE OF "+c+" = "+(int)c);
}
}
}
import java.util.*;

public class q7
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String;");
String S = in.nextLine();
String s = S.trim();
int l = s.length();
String news = "";
for (int i = 0; i < l; i++)
{
char c = s.charAt(i);
if ("aeiouAEIOU".indexOf(c) != -1)
news = news + '*';
else
news = news + c;
}
System.out.println(news);
}
}
import java.util.*;

public class q8
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sen = in.nextLine();
String S = sen.trim();
String s = ' ' + S;
int l = s.length();
String w = "";
for (int i = 0; i < l; i++)
{
char c = s.charAt(i);
if (c == ' ') {
w = w + s.charAt(i + 1);
}
}
System.out.println(w);
}
}
import java.util.*;

public class q9
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sen = in.nextLine();
String S = sen.trim();
String s = S + ' ';
int l = s.length();
String wr = "";
String wo = "";
for (int i = 0; i < l; i++)
{
char c = s.charAt(i);
if (c != ' ')
{
wr = c + wr;
wo = wo + c;
} else if (c == ' ')
{
if (wr.equals(wo))//wr==wo
System.out.println(wo);
wr = "";
wo = "";
}
}
}
}
import java.util.*;
import java.util.*;

public class q10


{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sen = in.nextLine();
String S = sen.trim();
String s = S + ' ';
int l = s.length();
String r = "";
String w = "";
for (int i = 0; i < l; i++)
{
char c = s.charAt(i);
if (c != ' ')
w = w + c;
else
{
r = w + ' ' + r;
w = "";
}
}
System.out.println(r);
}
}

You might also like