0% found this document useful (0 votes)
5 views19 pages

Computer Practical Work 22

The document contains a series of Java programming exercises aimed at 10th-grade students, covering topics such as tech numbers, student records, departmental sales, vowel counting, string manipulation, and letter frequency analysis. Each exercise includes a problem statement, a Java program implementation, and a description of variable types and their purposes. The document serves as a practical guide for students to enhance their programming skills through hands-on coding tasks.

Uploaded by

sahuniraj0912
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)
5 views19 pages

Computer Practical Work 22

The document contains a series of Java programming exercises aimed at 10th-grade students, covering topics such as tech numbers, student records, departmental sales, vowel counting, string manipulation, and letter frequency analysis. Each exercise includes a problem statement, a Java program implementation, and a description of variable types and their purposes. The document serves as a practical guide for students to enhance their programming skills through hands-on coding tasks.

Uploaded by

sahuniraj0912
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/ 19

1|Page

COMPUTER
PRACTICAL
WORK

NAME :- PIYUSH SAHU


STD :- 10TH B
ROLL NO :- 11
2|Page

PROGRAM PROGRAM PAGE NUMBER


NUMBER DEFINATION
1. A tech number has
even number of digits.
If the number is split
in two
equal halves, then the
square of sum of these
halves is equal to the
number itself. Write a
program to generate
and print all four
digits tech
numbers
2. A Class Teacher wants
to keep the records of
50 students of her class
along
with their names and
marks obtained in
English, Hindi, Maths,
Science and
Computer Science in a
Double Dimensional
Array (DDA) as M[50]
[6].
When the teacher
enters the name of a
student as an input,
the program must
display the name,
marks obtained in the
6 subjects and the
total. Write a program
in Java to perform the
task.
3. A Departmental Shop
has 5 stores and 6
departments. The
monthly sale of
the department is kept
in the Double
3|Page

Dimensional Array
(DDA) as m[5][6].
The Manager of the
shop wants to know
the total monthly sale
of each store and
each department at
any time. Write a
program to perform
the given task
4. Write a program to
input a sentence and
display the word of the
sentence that
contains maximum
number of vowels
5. Write a program to
accept a word and
convert it into lower
case, if it is in
upper case. Display the
new word by replacing
only the vowels with
the letter
following it.
6. Write a program to
input a sentence.
Count and display the
frequency of each
letter of the sentence in
alphabetical order
7. Write a program to
accept a string.
Convert the string into
upper case letters.
Count and output the
number of double
letter sequences that
exist in the string
4|Page

1.A tech number has even number of digits. If the number is split in two
equal halves, then the square of sum of these halves is equal to the number
itself. Write a program to generate and print all four digits tech numbers

import java.util.Scanner;
public class technum
{
public static void main(String args[])
{
int n, num, firstHalf, secondHalf, numberOfDigits=0,
squareOfTwoHalves;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number: ");
//Store the input number into variable num
n = scan.nextInt();
//copying the value of n into a new variable num
num = n;

//Here we are finding the number of digits in the input number


while (num > 0)
{
numberOfDigits++;
num = num / 10;
}
//If the number of digits are not even return "Not a Tech Number"
if (numberOfDigits % 2 == 0)
{
num = n;
//Splitting the number in two halves
firstHalf = num % (int) Math.pow(10, numberOfDigits / 2);
secondHalf = num / (int) Math.pow(10, numberOfDigits / 2);
//calculate the sum of the square of two halves
squareOfTwoHalves = (firstHalf + secondHalf) * (firstHalf +
secondHalf);
//compare the result with the number itself.
if (n == squareOfTwoHalves)
{
System.out.println(n +" is a Tech number.");
}
else
{
5|Page

System.out.println(n +" is not a Tech number.");


}
}
else
{
System.out.println(n + " is not a Tech number.");
}
}
}

OUTPUT:-

VARIABLE NAME VARIABLE TYPE DESCRIPTION

n Int to input value and


count for given
program
num Int To change for given
integer
firstHalf Int To count value of first-
half of the given value
secondHalf Int To count value second-
half of the given value
numberOfDigits Int To calculate given
string for program
squareOfTwoHalves Int To calculate the square
of the two halves given
6|Page

2. A Class Teacher wants to keep the records of 50 students of her class


along with their names and marks obtained in English, Hindi, Maths,
Science and Computer Science in a Double Dimensional Array (DDA) as
M[50][6].When the teacher enters the name of a student as an input, the
program must display the name, marks obtained in the 6 subjects and the
total. Write a program in Java to perform the task.

import java.util.Scanner;

public class StudentRecord


{
public static void main(String args[]) {
final int TOTAL_STUDENTS = 50;
final int TOTAL_SUBJECTS = 6;
final String SUBJECT_NAMES[] = {"English", "Hindi",
"Maths", "Science", "Computer Science"};
Scanner in = new Scanner(System.in);
String names[] = new String[TOTAL_STUDENTS];
int marks[][] = new int[TOTAL_STUDENTS][TOTAL_SUBJECTS];
int i = 0, j = 0;
for (i = 0; i < TOTAL_STUDENTS; i++) {
System.out.println("Student " + (i + 1) + " details:");
System.out.print("Name: ");
names[i] = in.nextLine();
for (j = 0; j < TOTAL_SUBJECTS; j++) {
System.out.print("Enter marks in " +
SUBJECT_NAMES[j] + ": ");
marks[i][j] = in.nextInt();
}
in.nextLine();
}
System.out.print("\nEnter name of the student to search: ");
String studentName = in.nextLine();
for (i = 0; i < TOTAL_STUDENTS; i++) {
if (names[i].equals(studentName))
break;
}
if (i == TOTAL_STUDENTS) {
7|Page

System.out.println("Record for " + studentName


+ " not found");
}
else {
System.out.println("Name: " + names[i]);
int total = 0;
for (j = 0; j < TOTAL_SUBJECTS; j++) {
System.out.println("Marks in " +
SUBJECT_NAMES[j] + ": " + marks[i][j]);
total += marks[i][j];
}
System.out.println("Total Marks: " + total);
}
}
}

VARIABLE NAME VARIABLE TYPE DESCRIPTION


TOTAL_STUDENTS int to input value and
count total number of
students
TOTAL_SUBJECTS int to input value and
count total number of
subjects
SUBJECT_NAMES String
names String
marks int to input value and
count marks for given
students
i int to input value as the
TOTAL_STUDENTS
for array
j int to input value as the
TOTAL_SUBJECTS
for arrays
8|Page

OUTPUT :-
9|Page

3.A Departmental Shop has 5 stores and 6 departments. The monthly sale
of the department is kept in the Double Dimensional Array (DDA) as m[5]
[6].The Manager of the shop wants to know the total monthly sale of each
store and each department at any time. Write a program to perform the
given task

import java.util.Scanner;

public class DepartmentalStore


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
Long m [][] = new long[5][6];
for (int i = 0; i < 5; i++) {
System.out.println("Store " + (i + 1) + " Sales");
for (int j = 0; j < 6; j++) {
System.out.print("Enter monthly sale of department " +
(j + 1) + ": ");
m[i][j] = in.nextLong();
}
}
System.out.println("\nMonthly Sale by store: ");
for (int i = 0; i < 5; i++) {
long storeSale = 0;
for (int j = 0; j < 6; j++) {
storeSale += m[i][j];
}
System.out.println("Store " + (i + 1)
+ " Sales: " + storeSale);
}
System.out.println("\nMonthly Sale by Department: ");
for (int i = 0; i < 6; i++) {
long deptSale = 0;
for (int j = 0; j < 5; j++) {
deptSale += m[j][i];
}
System.out.println("Department " + (i + 1)
+ " Sales: " + deptSale);
}
10 | P a g e

}
}

OUTPUT:-
11 | P a g e

VARIABLE NAME VARIABLE TYPE DESCRIPTION

m Long to input value for given


array
j Long To input value for
given array
i Int To count value of given
integer
storeSale Long To calculate total sales
of stores of the given
program
deptSale Long To calculate total sales
of all departments of
given program
12 | P a g e

4.Write a program to input a sentence and display the word of the sentence
that contains maximum number of vowels

import java.util.Scanner;

public class VowelWord


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str + " ";
String word = "", mWord = "";
int count = 0, maxCount = 0;
int len = str.length();
for (int i = 0; i < len; i++) {
char ch = Character.toUpperCase(str.charAt(i));
if (ch == 'A' ||
ch == 'E' ||
ch == 'I' ||
ch == 'O' ||
ch == 'U') {
count++;
}
if (ch == ' ') {
if (count > maxCount) {
maxCount = count;
mWord = word;
}
word = "";
count = 0;
}
else {
word += ch;
}
}
13 | P a g e

System.out.println("The word with maximum number of vowels: "


+ mWord);
}
}

OUTPUT :-

VARIABLE NAME VARIABLE TYPE DESCRIPTION

count Int to input value and


count for given
program
str String To change the case for
given integer
ch char To count value of given
character
len Int To calculate length of
the given value
word String To calculate given
string for program
i Int To input value given
14 | P a g e

5. Write a program to accept a word and convert it into lower case, if it is in


upper case. Display the new word by replacing only the vowels with the
letter following it.

import java.util.Scanner;

public class VowelReplace


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);

if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {

char nextChar = (char)(ch + 1);


newStr = newStr + nextChar;

}
else {
newStr = newStr + ch;
}
}

System.out.println(newStr);
}
}
15 | P a g e

OUTPUT :-

VARIABLE NAME VARIABLE TYPE DESCRIPTION

newStr String to input value for given


string
str String To change the case for
string letter
ch char To count value of given
character
len Int To calculate length of
the given value
i Int To input value given
char Int To calculate letter
given character
16 | P a g e

6.Write a program to input a sentence. Count and display the frequency of


each letter of the sentence in alphabetical order

public class LetterFreq


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str.toUpperCase();
int freqMap[] = new int[26];
int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);
if (Character.isLetter(ch)) {
int chIdx = ch - 65;
freqMap[chIdx]++;
}
}

System.out.println("Character\tFrequency");
for (int i = 0; i < freqMap.length; i++) {
if (freqMap[i] > 0) {
System.out.println((char)(i + 65)
+ "\t\t" + freqMap[i]);
}
}
}
}
17 | P a g e

OUTPUT :-

VARIABLE NAME VARIABLE TYPE DESCRIPTION

freqMap Int to input value for


program
Str String To change the case for
given integer
ch char To count value of given
character
len Int To calculate length of
the given value
i Int To input value given
chIdx Int To calculate letter
given matrix
18 | P a g e

7. Write a program to accept a string. Convert the string into upper case
letters. Count and output the number of double letter sequences that exist
in the sequences that exist in the string

import java.util.Scanner;

public class LetterSeq


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();
String str = s.toUpperCase();
int count = 0;
int len = str.length();

for (int i = 0; i < len - 1; i++) {


if (str.charAt(i) == str.charAt(i + 1))
count++;
}

System.out.println("Double Letter Sequence Count = " + count);

}
}

OUTPUT :-
19 | P a g e

VARIABLE NAME VARIABLE TYPE DESCRIPTION


s String to input value for S
str String To change the case for
S integer
count Int To count value of input
len Int To calculate length of
the given value

You might also like