class 11 COMPUTER PROJECT solution
class 11 COMPUTER PROJECT solution
Question 1:Write a program in java to input a sentence in uppercase and frame a word by adding the first letter of
each word and also arrange the letters of the new word in an alphabetical order. Display the new word and arranged
word.
}
System.out.println("original string"+st);
System.out.println("original string"+st1);
char ch1,ch2;
String alpha="";
for(int i=65;i<=90;i++)
{
for(int j=0;j<st1.length();j++)
{
ch1=st1.charAt(j);
if(ch1==(char)i)
{
alpha=alpha+ch1;
}
}
}
System.out.print("String in alphabetical order"+alpha);
}
}
Question 2:Write a program in Java to accept a sentence and display each word of the sentence in Piglatin form.
Question 3:Write a program in Java to accept a sentence. Display the new sentence after reversing the characters of
each word.
}
}
Question 4: Write a program in Java to accept a string terminated by full stop. Arrange all the words in descending
order of their lengths. Same length of words should be sorted alphabetically. Each word must start with uppercase
and the sentence should be terminated by full stop.
}
StringTokenizer st = new StringTokenizer(ss);
int count = st.countTokens();
String a[] = new String[count];
for(int i = 0; i < count; i++)
{
a[i] = st.nextToken();
}
for(int i = 0; i < a.length; i++)
{
for(int j = 0; j < a.length - 1 - i; j++)
{
if(a[j].length() != a[j + 1].length())
{
if(a[j].length() < a[j + 1].length())
{
String temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
else
{
if(a[j].compareTo(a[j + 1]) > 0)
{
String temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + " ");
}
System.out.print(".");
}
}
Question 5: Write a program in Java to accept a String and display the character, which occurs maximum number of
times in the String. Display the frequency of the character also.
import java.util.*;
public class fre_max_char
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("enter the string ");
String st=s.nextLine();
String st1="";
char ch1,ch2,max_char=0;
int len=st.length();
st=st.toLowerCase();
int count=0, max=0;
for(int i = 0; i <st.length()-1; i++)
{
ch1 = st.charAt(i);
for(int j=0;j<st.length();j++)
{
ch2 = st.charAt(j);
if((ch1==ch2)&&(ch1!=' ') )
{
count++;
}
}
if(count>0)
{
System.out.println(ch1 +" "+count);
if(count>max)
{
max=count;
max_char=ch1;
}
}
count=0;
st=st.replace(ch1,' ');
}
System.out.println("max occurance of character is"+max_char+" "+max);
}}
Question 6:Write a program in Java to accept a sentence and display all the consecutive and repeated present in the
given sentence.
Sample Input: understanding computer science Sample Output: Consecutive Characters: de, rs, st
Repeated Characters: u, n, e, r, s, t, i, c
import java.util.Scanner;
class consecutive_repeated
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("enter the string ");
String st=s.nextLine();
String st1="";
char ch1,ch2;
int len=st.length();
st=st.toLowerCase();
String consecutive = "";
st1=st1+" "+ch1;//ce
st=st.replace(ch1,' ');//n""""
}
}}
System.out.println("repeated characters:\n" + st1);
}
}
Question 7:Write a program in Java to accept a word and arrange all the letters in ascending order. Display the
missing letters in the sequence of the arranged word.
Sample Input: DELHI Arranged word: DEHIL Sample Output: FGJK
import java.util.Scanner;
}
for(int i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch!=' ')
missing_letters=missing_letters+ch;
}
Solution: 22 + 22 + 12 + 22 + 0 = 13 ⇒ 12 + 32 = 10 ⇒
[Hint: A=1, B=2 … , Z=26]
12 + 0 = 1
Sample Output: A Happy Word
import java.util.Scanner;
if (isHappy)
System.out.println("A Happy Word");
else
System.out.println("Not a Happy Word");
}
}
Question 9:Write a program in Java to input a sentence. Convert the sentence to Uppercase. Count and display the
words those have at least a pair of consecutive letters.
char ch1,ch2;
st=st.toLowerCase();
String consecutive = "";
StringTokenizer ss=new StringTokenizer(st);
String st1="",st2="";
int len=0,count=0;
char ch;
while(ss.hasMoreTokens())
{
st1=ss.nextToken();
len=st1.length();
System.out.println(st1);
}}
}
}}
Write a program to accept a sentence which may be terminated by either ‘.’ or ‘?’ only. The words are to be
separated by a single blank space. Print an error message if the input does not terminate with ‘.’ Or ‘?’. You can
assume that no word in the sentence exceeds 15 characters, so that you can get a proper formatted output. Perform
the following tasks:
Convert the first letter of each word to uppercase
Find the number of vowels and consonants in each word and display them with proper headings along with the
words.
Example 1
Sample Input: Intelligence plus character is education. Sample Output: Intelligence Plus Character Is Education.
Word Vowels Consonants
Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4
Example 2
Sample Input: God is great. Sample Output: God Is Great
Word Vowels Consonants
God 1 2
Is 1 1
Great 2 3
Example 3
Sample Input: All the best! Sample Output: Invalid Input
import java.util.Scanner;
public class StringProgram
{
public static void main(String args[])
{
String sen="",wd="",upper="";
char ch=' ',last=' ';
int i=0,len=0,vowelsFrequency=0,consonantsFrequency=0;
Scanner sc=new Scanner(System.in);
System.out.print("String: ");
sen = sc.nextLine();
sen = sen.trim();
len = sen.length();
last = sen.charAt(len - 1);
if(last != '.' && last != '?')
{
System.out.println("Invalid input.");
}
else
{
System.out.println("Word\tVowels\tConsonants");
for(i = 0; i < len; i++)
{
ch = sen.charAt(i);
if(ch == ' ' || ch == '.' || ch == '?')
{
wd=Character.toUpperCase(wd.charAt(0))+wd.substring(1).toLowerCase();
System.out.println(wd+"\t"+vowelsFrequency+"\t"+consonantsFrequency);
wd = "";
vowelsFrequency=0;
consonantsFrequency=0;
}
else
{
wd += ch;
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
vowelsFrequency++;
}
else
{
consonantsFrequency++;
}
}
}
}
}
}