DXC Technology Automata Fix Questions

10 May 2023

 

Q1) Print the Statement [Java Programming]

Debug the error:

The code has been commented. Uncomment the code and debug it.


import java.io.*;

class Main { /*

  public static main (String[] args) {

  System.out.println("CTS Automata");

  } */

}

Sample Output:

CTS Automata

Case 1

Input (stdin)

Output (stdout)

CTS Automata
Solution :

import java.io.*;

class Main {

  public static void main (String[] args) {

  System.out.println("CTS Automata");

  }

}

Q2) Array matrix of dimension [Java Programming]

The function calculateMatrixSum(int matrix, int m, int n) accepts a two dimensional array matrix of dimensions m, n as input and returns the sum of odd elements whose i and j index are same. The function compiles fine but fails to return the desired result for some test cases.

The code has been commented. Uncomment the code and debug it.


import java.util.*;

class Main {

  static int calculateMatrixSum(int matrix[][], int m, int n)

{   int sum=0;

  /*  int i,j,row=m, column=n;

    if((row>0)&&(column>0))

    {

        for(i=0;i<row;i++)
     

  {

  for(j=0;j<column;j++)

            {

                if(i==j)

                {

                    if( matrix[i][j] % 2 == 0)

                    sum+=matrix[i][j];

                }

            }

        }

    } */

    return sum;

}

public static void main (String[] args) {

   Scanner sc=new Scanner(System.in);

       int rows=sc.nextInt();

       int columns=sc.nextInt();

       int twoD[][]=new int[rows][columns];

        for(int i=0; i<rows;i++)

         {           

            for(int j=0; j<columns;j++)

            {

                twoD[i][j]=sc.nextInt();

            }

         }

         System.out.println(calculateMatrixSum(twoD,rows,columns));

  }

}

Sample input :

2

2

7 2

2 3

Output:

10

Case 1

Input (stdin)


2

2

7 2

2 3

Output (stdout)

10
Solution:

import java.util.*;

class Main {

  static int calculateMatrixSum(int matrix[][], int m, int n)

{

    int i,j,sum=0,row=m, column=n;

    if((row>0)&&(column>0))

    {

        for(i=0;i<row;i++)

        {

  for(j=0;j<column;j++)

            {

                if(i==j)

                {

                    if( matrix[i][j] % 2 != 0)

                    sum+=matrix[i][j];

                }
       }

        }

    }

    return sum;

}

public static void main (String[] args) {

   Scanner sc=new Scanner(System.in);

       int rows=sc.nextInt();

       int columns=sc.nextInt();

       int twoD[][]=new int[rows][columns];

        for(int i=0; i<rows;i++)

         {           

            for(int j=0; j<columns;j++)

            {

                twoD[i][j]=sc.nextInt();

            }

         }

         System.out.println(calculateMatrixSum(twoD,rows,columns));

  }

}

Q3) Display Characters from A to Z [Java Programming]

Write a Program to Display Characters from A to Z using loop.

The code has been commented. Uncomment the code and debug it.


import java.util.Scanner;

class Main { /*

    public static void main(String[] args) {

        char c;

        for(c = 'A'; c < 'Z'; ++c)

            System.out.println(c + " ");

    } */

}

Sample Output:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Case 1

Input (stdin)



Output (stdout)

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Solution:

import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        char c;

        for(c = 'A'; c <= 'Z'; ++c)

            System.out.print(c + " ");

    }

}

Q4) Eliminate all the vowels [C++ Programming]

Given a string str, write a program to eliminate all the vowels from the given string. The list of vowels in the English alphabet is : {a,e,i,o,u,A,E,l,0.U}. The Input to the function eliminate Vowel String shall consist of a string str (containing only English letters).

EXAMPLE:


Input =”abcdefghijklmnopqrstuvwxyz”

0utput="bcdfghjklmnpqrstvwxyz”

USEFUL COMMANDS:

Strlen() is used to calculate the length of the string.

The statement -

int len = strlen(str); Returns the length of the string str.

#include<iostream>

#include<stdlib.h>

#include<string.h>

using namespace std;

void consonants(char *str)

{

    //Type your code here

}

int main()

{

    char str[100];

    scanf("%s",str);

    consonants(str);

    return 0;

}

Sample Input:

bacdefghijklmnopgrstu

Output:

Bcdfghjklmnpqrst

Case 1

Input (stdin)


abcdefghijklmnopqrstuvwxyz

Output (stdout)

bcdfghjklmnpqrstvwxyz
Solution:

#include<iostream>

#include<stdlib.h>

#include<string.h>

using namespace std;

void consonants(char *str)

{

    int len = strlen(str);

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

    {

    if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o' || str[i]=='u'||str[i]=='A'||str[i]=='E‘ ||str[i]=='I'||str[i]=='O'||str[i]=='U')

            {

                continue;          

            }

            else

                printf("%c",str[i]);

    }

}

int main()

{

    char str[100];

    scanf("%s",str);

    consonants(str);

    return 0;

}

Q5) Find the Pattern[C Programming]

Write a program to print the following output. 


#include<stdio.h>

int pattern(int n)

{

   //Your code goes here

}

void main()

{

    int n;

    scanf("%d",&n);

    pattern(n);

}

Sample Input:

5

Output:

11111

1     1

1     1

1     1

11111

Case 1

Input (stdin)


5

Output (stdout)

11111

1   1

1   1

1   1

11111
Solution:

#include<stdio.h>

int pattern(int n)

{

    int i,j;

    for(i=1;i<=n;i++)

    {

        for(j=1;j<=n;j++)

        {

            if(i==1||i==n||j==1||j==n)

                printf("1");

            else

                printf(" ");

        }

        printf("\n");

    }

}

void main()

{

    int n;

    scanf("%d",&n);

    pattern(n);

}


FAQ

Any Questions?
Look Here.

Related Articles

Accenture Abstract Reasoning Previous Year Questions

Accenture Critical Reasoning and Problem Solving Questions

Accenture English Ability Previous Year Questions

Accenture MS Office Questions

Accenture Network Security & Cloud Computing Questions

Accenture Pseudocode Questions

Capgemini Game Based Aptitude Previous Year Questions

Capgemini Technical MCQ's Previous Year Questions

Cisco Aptitude Previous Year Questions

Cognizant Gen C Quantitative Ability Previous Year Questions

Dell Quantitative Aptitude Previous Year Questions

Dell Verbal Ability Previous Year Questions

Deloitte Quantitative Aptitude Previous Year Questions

DXC Technology Computer Programming Questions

DXC Technology Logical Ability Questions

DXC Technology Quantitative Ability Previous Year Questions

DXC Technology Verbal Ability Questions

Goldman Sachs Numerical Computation Previous Year Questions

Hexaware Logical Ability Previous Year Questions

Hexaware Numerical Ability Previous Year Questions

Hexaware Verbal Ability Previous Year Questions

Infosys Mathematical Ability Previous Year Questions

Infosys Pseudocode Questions

Infosys Puzzle Solving Previous Year Questions

Infosys Reasoning Ability Previous Year Questions

Infosys SP DSE Previous Year Questions

Infosys Verbal Ability Previous Year Questions

InfyTQ DBMS Questions

InfyTQ Java Questions

LTI Logical Reasoning Previous Year Questions

LTI Quantitative Ability Previous Year Questions

LTI Verbal Ability Previous Year Questions

Mindtree Previous Year Questions

TCS NQT Numerical Ability Questions

TCS NQT Previous Year Coding Questions

TCS NQT Verbal Ability Questions

Tech Mahindra Logical Ability Previous Year Questions

Tech Mahindra Quantitative Ability Previous Year Questions

Top 14 Capgemini Pseudocode Questions

Top 15 LTI Coding Questions

Top 15 TCS NQT Reasoning Questions

Wipro Logical Ability Questions

Wipro Quantitative Ability Previous Year Questions

Wipro Verbal Ability Questions