You are on page 1of 5

program 13- check . ? !

characters vertical , sentence horizontal

program 14- number of time each word occurs

Program 12
import java.util.*;
class Encrypt
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String s="",str="",str1="";;
int shift,value,i,l=0;
char ch,ch1,val;
System.out.println("Enter the code in uppercase");
s=sc.next();
s=s.toUpperCase();
System.out.println("Enter the shifting value");
shift=sc.nextInt();
for( i=0;i<l;i++)
{
ch=s.charAt(i);
value=(int)ch;
value=value+shift;
if(value>90)
value=value-26;
val=(char)value;
str=str+value;
}//close of for loop
for(i=0;i<l;i++)//checking if in the code 'qq' exists
{
ch=str.charAt(i);
ch1=str.charAt(i+1);
if(ch==ch1&&(ch1=='Q'||ch=='q'))
{
str1=str1+" ";//adding space in place of 'qq'
i++;
}//if
else
str1=str1+ch;
}//close of for loop
System.out.println(str1);
}//main
}//class

15?
import java.util.*;
class sentence2
{
Scanner sc=new Scanner(System.in);
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a sentence");
int l1;
String str=sc.nextLine();
String s="";
l1=str.length();
String w="";
for(int m=0;m<l1;m++)
{
char ch=str.charAt(m);
if(ch!='.')
{
w=w+ch;}
else
{
System.out.println();
s=w;
s+=" ";
int l=s.length();
String a="";
int max=0,n=0;
for(int i=0;i<l;i++)
{
char c=s.charAt(i);
if(c!=' ')
{
a+=c;
}
else
{
n+=1;
if(a.length()>max)
max=a.length();
a="";
}
char x[][]=new char[max][max];
i=0; int j=0,y=0;
while(y<l)
{
c=s.charAt(y);
if(c==' ')
{
for(int k=i;k<max;k++)
x[k][j]=' ';
j++;
i=0;
}
else
{
x[i][j]=c;
i++;
}
y++;
}
for(int p=0;p<max;p++)
for(int q=0;q<n;q++)
System.out.println(x[p][q]);
}
System.out.println();
}
w="";
}
}
}
16?
import java.util.*;
class words
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String str,w="";
int l,check=0;
char ch;

System.out.println("Enter the sentence");


str=sc.nextLine();
l=str.length();
char ch1[]=new char[l];
char ch2[]=new char[l];
ch=str.charAt(l-1);
if (ch=='?' || ch=='.'|| ch=='!')
check=0;
else
check =1;

if(check==1)
System.out.println("No full stop or exclamation mark or question mark
termination");
else
{
System.out.println("Output : ");
System.out.println(str);

}
}

//15 program
import java.util.*;
class Code
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n,l,i,j,x=0;
String s;
char ch,ch1;
System.out.println("Enter the length of the code");
n=sc.nextInt();
if (n>6)
{
System.out.println("Invalid.");
System.out.println("Reason-Length of the string should not exceed 6
characters");
System.exit(0);//terminates the program
}//if
System.out.println("Enter the code");
s=sc.next();
l=s.length();
if (l!=n)
{
System.out.println("Invalid.");
System.out.println("Reason- String length is not the same as
specified");
System.exit(0);
}//if
for (i=0;i<n;i++)
{
ch=s.charAt(i);
if (Character.isLowerCase(ch)==true)
{
System.out.println("Invalid.");
System.out.println("Reason-Only upper case letters permitted");
System.exit(0);
}//if
else
{
for(j=i+1;j<n;j++)
{
ch1=s.charAt(j);
if((int)ch==(int)ch1)//checks if there are 2 or more of the same
letter in the string
{
System.out.println("Invalid.");
System.out.println("Reason-Repetition of characters not permitted");
System.exit(0);
}//if
}//close of inner loop
}//else
}//close of outer loop
for (i=0;i<n;i++)
{
ch=s.charAt(i);
x=(int)ch;
System.out.println(x);
if (x>75)
{
System.out.println("Invalid.");
System.out.println("Reason-The range is from 'A' to 'K'");
System.exit(0);
}//if
for (j=66;j<=75;j=j+2)
{
if (x==j)
System.out.println(x+" "+j);
{
System.out.println("Invalid.");
System.out.println("Reason-Only alternate letters permitted");
System.exit(0);
}//if
}//close of inner loop
System.out.println("Valid");
}//close of outer loop
}//main
}//class
Number Program
import java.util.*;
class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int check=0,m;
System.out.println("Enter m");
m=sc.nextInt();
if (m<100 && m>10000)
check=1;
else
check=0;
System.out.println("Enter n");
int n=sc.nextInt();
if (n>100)
check=1;
else
check=0;
int val=m+1;
int sum=0;
int copy=val;
int d;
if (check==1)
System.out.println("Error");
else if (check==0)
{
while (check==0)
{
copy=val;
while (copy>0)
{
d=copy%10;
sum=sum+d;
copy=copy/10;
}
if (sum==n)
{
check =1;
System.out.println("OUTPUT - "+ val);
System.out.println("OUTPUT - "+ val);
}
else
{
System.out.println("?");
check=0;
sum=0;
val++;
}
}
}
}
}

You might also like