Professional Documents
Culture Documents
12th Record Programs
12th Record Programs
1)
Pseudo Code:
BEGIN
CLASS employee
READ String empname
READ int empcode
READ double basicpay
Source Code:
import java.util.*;
class employee
{
String empname;
int empcode;
double basicpay;
VDT:
FUNCTION MAIN()
SET limit=100
CALL FUNCTION P_T(limit)
END FUNCTION
END CLASS
END
Source Code:
import java.io.*;
import java.util.*;
class P_T {
int a, b, c = 0;
int m = 2;
while (c < limit)
{
for (int n = 1; n < m; ++n)
{
a = (m * m )- (n * n);
b = 2 * m * n;
c = (m * m) +(n * n);
if (c > limit)
break;
System.out.println(a + " " + b + " " + c);
}
m++;
}
}
public static void main(String args[])
{
int limit = 100;
P_T (limit);
}
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 a int To store
first
number of
triplet
2 b int To store
second
number of
triplet
3 c int To store
third
number of
triplet
4 Limit int To set
limit
5 m int To
calculate
triplet
6 n int Used in
‘for loop’
3)
Pseudo Code:
BEGIN
CLASS DDArray
READ int mat[][]= new int[50][50]
READ int m,n
FUNCTION readMatrix()
PRINT(“Enter matrix elements”)
FOR(int i=0; i<m; i++)
FOR (int j=0;j<n;j++)
INPUT=mat[i][j]
ENDFOR
ENDFOR
END FUNCTION
FUNCTION Sums()
SET int lsum=0, rsum=0, bound=0
FOR (int i=0;i<m;i++)
FOR(int j=0;j<n; j++)
IF(i==j)
THEN
COMPUTE lsum= lsum+mat[i][j]
ENDIF
ENDFOR
ENDFOR
FUNCTION Show_Mats()
PRINT(“Oringinal Matrix”)
FOR( int i=0; i<m; i++)
FOR(int j=0; j<n; j++)
PRINT (mat[i][j]+" ")
ENDFOR
PRINT()
ENDFOR
PRINT(“Inner Matrix”)
FOR( int i=0; i<m; i++)
FOR(int j=0; j<n; j++)
IF(i==0||i==(n-1)||j==0||j==(n-1))
PRINT(“ ”)
ENDIF
ELSE
PRINT(mat[i][j]+ “ ”)
END ELSE
ENDFOR
PRINT()
ENDFOR
END FUNCTION
FUNCTION MAIN()
PRINT(“Enter Rows and Columns”)
INPUT m
INPUT n
CALL FUNCTION DDArray(m,n)
CALL FUNCTION readMatrix()
CALL FUNCTION Sums()
CALL FUNCTION Show_Mats()
END FUNCTION
END CLASS
END
Source Code:
import java.io.*;
import java.util.*;
public class DDArray
{
static Scanner in=new Scanner(System.in);
int mat[][]=new int[50][50];
int m,n;
DDArray(int nr,int nc)
{
m=nr;
n=nc;
}
void readMatrix()
{
System.out.println("Enter matrix elements");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
mat[i][j]=in.nextInt();
}
}
}
void Sums()
{
int lsum=0,rsum=0, bound=0;
for(int i=0;i<m;i++)
{
for (int j=0;j<n;j++)
{
if(i==j)
lsum=lsum+mat[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i+j==n-1)
rsum=rsum+mat[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==(n-1)||j==0||j==(n-1))
bound=bound+mat[i][j];
}
}
System.out.println("Sum of left diagonal=
"+lsum);
System.out.println("Sum of right diagonal=
"+rsum);
System.out.println("Sum of boundary
elements= "+bound);
}
void Show_Mats()
{
System.out.println("Original Matrix");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
System.out.println("Inner Matrix");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||i==(n-1)||j==0||j==(n-1))
System.out.print(" ");
else
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
System.out.println("Enter rows and
cloumns");
int m= in.nextInt();
int n= in.nextInt();
DDArray obj= new DDArray(m,n);
obj.readMatrix();
obj.Sums();
obj.Show_Mats();
}
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 mat int To store
matrix
2 m int To store
no. of
rows
3 n int To store
no. of
columns
4 nr int To take
input for
no. of
rows
5 nc int To take
input for
no. of
columns
6 i int Used in
‘for loop’
7 j int Used in
‘for loop’
8 lsum int To
calculate
and store
sum of
left
diagonal
9 rsum int To store
sum of
right
diagonal
10 bound int To store
sum of
boundary
elements
4)
Pseudo Code:
BEGIN
CLASS Vowels
FUNCTION Sentences()
INPUT STREAM READER in
BUFFERED READER br
PRINT(“Enter a sentence”)
SET String sentence= br.readLine()
COMPUTE sentence= sentence.toUpperCase()
SET StringTokenizer st1=new
StringTokenizer(sentence, ".?!");
COMPUTE int count st1.countTokens()
IF(count>10)THEN
PRINT (“Maximum 10 sentences allowed.”)
RETURN
ENDIF
END FUNCTION
FUNCTION MAIN()
CALL FUNCTION Sentences()
END FUNCTION
END CLASS
END
Source Code:
import java.io.*;
import java.util.StringTokenizer;
class Vowels
{
void Sentences()throws IOException
{
InputStreamReader in = new
InputStreamReader(System.in);
BufferedReader br = new
BufferedReader(in);
System.out.println("Enter sentence:");
String sentence = br.readLine();
sentence = sentence.toUpperCase();
StringTokenizer st1 = new
StringTokenizer(sentence, ".?!");
int count = st1.countTokens();
if(count > 10)
{
System.out.println("Maximum 10
sentences allowed.");
return;
}
String str[] = new String[count];
int a[] = new int[count];
int b[] = new int[count];
for(int i = 0; i < str.length; i++)
str[i] = st1.nextToken();
for(int i = 0; i < str.length; i++)
{
StringTokenizer st2 = new
StringTokenizer(str[i], " ");
a[i] = st2.countTokens();
for(int j = 0; j < str[i].length(); j++)
{
char ch = str[i].charAt(j);
switch(ch){
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
b[i]++;
}
}
}
System.out.println("Sentence\tNo. of
Vowels\tNo. of Words");
for(int i = 0; i < str.length; i++)
System.out.println((i + 1) + "\t"+"\t" + b[i]
+ "\t"+"\t" + a[i]);
System.out.println("Sentence\tNo. of
Vowels/Words");
for(int i = 0; i < str.length; i++)
{
System.out.print((i + 1) + "\t\t");
for(int j = 0; j < b[i]; j++)
System.out.print("VVV");
System.out.println();
System.out.print("\t"+"\t");
for(int j = 0; j < a[i]; j++)
System.out.print("WWW");
System.out.println();
}
}
public static void main(String args[])throws
IOException
{
Vowels obj= new Vowels();
obj.Sentences();
}
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 sentence String To take input
from user
2 St1 StringTokenizer To transfer the
input to
SringTokenizer
to count the
number of
sentences
3 count int To store the
number of
sentences
4 str Array(String) To take each
letter of the
input in array
form
5 a Array(int) To calculate
the number of
words in each
sentence
6 b Array(int) To calculate
number of
vowels in each
sentence
7 i int Used in ‘For
loop’
8 j Int Used in ‘For
loop’
9 St2 StringTokenizer To take each
word of the
input in array
form
10 ch Char Used as input
for switch case
to find out the
number of
vowels present
in each word
5)
Pseudo Code:
BEGIN
CLASS DECODE
READ String Decryptmsg
READ int[] codeValues
FUNCTION reverseString()
SET int j= 0
FOR(int i = Decryptmsg.length()-1; i >= 0; i--)
COMPUTE codeValues[j++]=
Decryptmsg.charAt(i)-48
END FOR
END FUNCTION
FUNCTION decryptCode()
READ int tmp
SET i= 0
WHILE(i< Decryptmsg.length())
THEN
IF (i < Decryptmsg.length() && i+1 <
Decryptmsg.length() && i+2 <
Decryptmsg.length())
THEN
COMPUTE tmp =
codeValues[i]*10*10+codeValues[i+1]*10+code
Values[i+2];
ELSE
tmp = codeValues[i]*10+codeValues[i+1];
END IF
IF(tmp>=&& tmp<=122)
THEN
PRINT((char)tmp)
i+ =3
END IF
ELSE
PRINT((char)tmp)
IF(tmp==32)
PRINT(“ ”)
i+ =2
END IF
END WHILE
END FUNCTION
FUNCTION MAIN()
READ String msg
SET BufferedReader br= new BufferedReader()
PRINT(“Enter the encoded message”)
SET msg= br.readLine()
CALL FUNCTION Decrypt(msg)
CALL FUNCTION reverseString()
PRINT(“Output: The Decoded Message”)
CALL FUNCTION decryptCode()
END FUNCTION
END CLASS
END
Source Code:
import java.util.*;
import java.io.*;
public class DECODE {
String Decryptmsg;
int[] codeValues;
}
Output:
VDT:
Sl.No Variable Datatype Objective
1 Decryptmsg String Used to
perform
various
functions in
order to obtain
the decoded
message
2 codeValues Array(int) To store the
encoded
message in an
array
3 msg String To get the
input(Encoded
message)
from the user
4 i Int Used in ‘For
Loop’
5 j Int Used in ‘For
Loop’
6 tmp int Used in
converting the
numbers to
corresponding
ASCII value