Skip to main content

Mission "TCS DIGITAL" ( Upgrade Ninja to Digital ) previous year Coding Quistion 02

 Problem 2 : 





Subscribe Please : click here


Q2 :


Sum of the digits of the given positive integer number N is UNO or not.



Problem Statement : 


Given a positive integer number N, reduce the number of digits of N by computing the sum of all the digits to get a new number. If this new number exceeds 9, then sum the digits of this new number to get another number and continue this way until a single digit value is obtained as the ‘digit sum’. The task here is to find out whether the result of the digit sum done this way is ‘1’ or not. If the result is 1 return UNO else not.


Input : 254


output : not


Input : 235


output : UNO


Explation :


1. 254 = 2+5+4 = 11 

2. 11>9

3. 11 = 1+1 = 2

4. 2<9 but not 1 so 

5. output "NOT"



1. 235 = 2+3+5 =10

2. 10>9

3. 10 = 1+0 = 1

4. 1<9 and sum=1 so

5. output "UNO"



Code : 


import java.util.Scanner;

public class Problem2 {
    public static void main(String[] args) {
         Scanner sc=new Scanner(System.in);

         int n=sc.nextInt();

         int sum=0;

         while(n!=0 || sum>9){
            if(n==0){
                n=sum;
                sum=0;
            }
            int d=n%10;
            sum+=d;
            n/=10;
         }

         if(sum==1){
            System.out.println("UNO");
         }
         else{
            System.out.println("NOT");
         }
    }
}



Comments

Popular posts from this blog

Complete Strategy to clear TCS Xplore IPA in One Attempt Now ( 80+ Score )

  So hello Everyone , Here are the all Links from where you can Practice !  All the resources are searched from my best !  1. For KYT and Bizzskill  Link :- tcs Xplore course  2. Unix Operating system Link :-    a.  click here Link 1 b.  click here Link 2 c.  Click here Link 3   3. UI  Link :-  click here 4. SQL and Pl SQL Link : -  Click here Click here click here 5. Java MCQ  Link :-  click here click here click here 6. Java coding :-  Access the playlist on YouTube :-  click here to watch Access the blogs :-  click here All in one link :-   click here

TCS IPA previous year quistion ( 35 marks ) , Quistion , Input , output

 Problem Statement Video Link :    https://youtu.be/XCBvfJAo908 Create a class TravelAgencies with below attributes: regNo – int agencyName – String pakageType – String price – int flightFacility – boolean Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence. Create class Solution with main method. Implement two static methods – findAgencyWithHighestPackagePrice and agencyDetailsforGivenIdAndType in Solution class. findAgencyWithHighestPackagePrice method: This method will take array of TravelAgencies objects as an input parameter and return the highest package price from the given array of objects. agencyDetailsForGivenldAndType method: This method will take three input parameters -array of TravelAgencies objects, int parameter regNo and String parameter packageType. The method will return the TravelAgencies object based on below conditions. FlightFacility should be available. The input parameters(regNo and packageType) shoul

TCS IPA previous year problems solved [input + output ] in JAVA - (35 marks )

  Problem Statement :  Video Link :   Click Here Create a class AutonomousCar with the below attributes: carld – int brand – String   noOfTestsConducted – int noOfTestsPassed- int environment – String grade – String Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence except grade. Create class Solution with main method. Implement two static methods – findTestPassedByEnv and updateCarGrade in Solution class. findTestPassedByEnv method: This method will take two input parameters -array of AutonomousCar objects and string parameter environment. The method will return the sum of the noOfTestsPassed attribute from autonomousCar objects for the environment passed as parameter. If no autonomousCar with the given environment is present in the array of AutonomousCar objects, then the method should return 0. updateCarGrade method: This method will take a String parameter brand, along with the array of AutonomousCar objects. The method