07A-2015 – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Exam Questions-ICSE2015-07A #JAVA#7368    siteicon   siteicon  

Problem Statement - 07A-2015

Design a class to overload a function Joystring() as follows: [15]
(i) void Joystring(String s, char ch1, char ch2) with one string and two character arguments that replaces the character argument ch1 with
the character argument ch2 in the given string s and prints the new string
Input value of s = “TECHNALAGY”
ch1 = ‘A’
ch2 = ‘O’
(ii) void Joystring(String s) with one string argument that prints the position of the first space and the last space of the given String s.
Input value of = “Cloud computing means Internet based computing”
First Index : 5
Last Index : 36
(iii) void Joystring(String s1, String s2) with two string arguments that combines the two strings with a space between them and prints the
resultant string
Example :
Input value of s1 = “COMMON WEALTH”
s2 = “GAMES”
(use library functions)


TC++ #7368

import java.util.Scanner;

 public class StringOperations {
 public void Joystring(String s, char ch1, char ch2) {
 String output = s.replace(ch1, ch2);
 System.out.println("Output = " + output);

 public void Joystring(String s) {
 int firstIndexOfSpace = s.indexOf(' ');
 int lastIndexOfSpace = s.lastIndexOf(' ');
 System.out.println("First index of space = " + firstIndexOfSpace);
 System.out.println("Last index of space = " + lastIndexOfSpace);

 public void Joystring(String s1, String s2) {
 String output = s1.concat(" ").concat(s2);
 System.out.println("Output = " + output);

 public static void main(String[] args) {
 Scanner scanner = new Scanner(System.in);
 StringOperations stringOperations = new StringOperations();

 // Joystring method 1
 System.out.print("Enter string: ");
 String s1 = scanner.nextLine();
 System.out.print("Enter ch1: ");
 char ch1 = scanner.nextLine().charAt(0);
 System.out.print("Enter ch2: ");
 char ch2 = (char) scanner.nextLine().charAt(0);
 stringOperations.Joystring(s1, ch1, ch2);

 // Joystring method 2
 System.out.print("Enter string: ");
 String s2 = scanner.nextLine();

 // Joystring method 3
 System.out.print("Enter s1: ");
 String s3 = scanner.nextLine();
 System.out.print("Enter s2: ");
 String s4 = scanner.nextLine();
 stringOperations.Joystring(s3, s4);


CSKC| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2015