In below we are providing Solutions for DCA 28th Sep 2021 for your reference.
Question 1:
A faulty program stores values from the username and password fields as a continuous sequence of characters. When trying to fetch either the username or password, the entire string is displayed Given the string str, the task here is to find and extract only the letters and special characters from the whole string stored.
Note:
The letters and special characters should be displayed separately.
The output should consist of all the letters, followed by all the special characters present in the input string.
Solution : (Java)import java.util.Scanner; public class Technoname { static String Result(String s) { String alphabets="",specialCharacter=""; for(int i=0;i<s.length();i++) { if((s.charAt(i)>='A'&& s.charAt(i)<='Z') || (s.charAt(i)>='a'&& s.charAt(i)<='z')) { alphabets+=s.charAt(i); } else if(!(s.charAt(i)>='0'&& s.charAt(i)<='9')) { specialCharacter+=s.charAt(i); } } return alphabets+specialCharacter; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); System.out.println(Result(s)); } }
2. Question
Kids up to the age of 7 are confused formation of letters and numbers, teacher uses the different methodologies to make the concepts of mathematics clear to the students. One of the methods the teacher uses to emphasis on the addition and recognition of numbers is that she muddles up the numbers randomly and then asks the students to find difference between adjacent digits. The task here to find given number is CORRECT or INCORRECT.
Solution:
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int number; cin>>number; number=abs(number); int remainder1=number%10; number=number/10; while(number>0) { int remainder2=number%10; if(abs(remainder1-remainder2)==1) { remainder1=remainder2; number=number/10; } else break; } if(number>0) cout<<"INCORRECT"; else cout<<"CORRECT"; return 0; }
0 Comments