C Programs Tutorials | IT Developer
IT Developer

Java Programs - Solved 2024 Theory Paper ISC Computer Science



Share with a Friend

Solved 2024 Thory Paper ISC Computer Science

Class 12 - ISC Computer Science Solved Theory Papers

Lowest & Highest ASCII Value Program - ISC 2024 Theory

Design a class Coding to perform some string related operations on a word containing alphabets only.

 

Example:
INPUT: “Java”


OUTPUT:
Original word: Java
J = 74
a = 97
v = 118
a = 97
Lowest ASCII code: 74
Highest ASCII code: 118

 

Some of the members of the class are given below.

Class name: Coding
Data members/instance variables:
wrd: stores the word
len: stores the length of the word


Methods/Member functions:
Coding(): constructor to initialize the data members with legal initial values
void accept(): to accept a word
void find(): to display all the characters of ‘wrd’ along with their ASCII codes. Also display the lowest ASCII code and the highest ASCII code, in ‘wrd’

 

void show(): to display the original word and all the characters of ‘wrd’ along with their ASCII codes. Also display the lowest ASCII code and the highest ASCII code in ‘wrd’, by invoking the function find()

Specify the class Coding giving details of the constructor(), void accept(), void find() and void show(). Define a main() function to create an object and call all the functions accordingly to enable the task.

import java.util.Scanner; class Coding{ String wrd; int len; public Coding(){ wrd = ""; len = 0; } public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Enter the word: "); wrd = in.next(); len = wrd.length(); } public void find(){ if(len == 0) return; int low = wrd.charAt(0); int high = wrd.charAt(0); for(int i = 0; i < len; i++){ char ch = wrd.charAt(i); int ascii = (int)ch; if(low > ascii) low = ascii; if(high < ascii) high = ascii; System.out.println(ch + " = " + ascii); } System.out.println("Lowest ASCII code: " + low); System.out.println("Highest ASCII code: " + high); } public void show(){ System.out.println("Original word: " + wrd); find(); } public static void main(String[] args) { Coding obj = new Coding(); obj.accept(); obj.show(); } }

Output

 
OUTPUT 1:
Enter the word: Java
Original word: Java
J = 74
a = 97
v = 118
a = 97
Lowest ASCII code: 74
Highest ASCII code: 118

OUTPUT 2:
Enter the word: ITDeveloper
Original word: ITDeveloper
I = 73
T = 84
D = 68
e = 101
v = 118
e = 101
l = 108
o = 111
p = 112
e = 101
r = 114
Lowest ASCII code: 68
Highest ASCII code: 118