PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION I/P: 3 O/P: 6 SOLUTION: package N umbers ; import java . util .*; public class Factorial { static int factorial ( int n ) { return ( n > 1 ) ? n * factorial ( n - 1 ) : 1 ; } public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); int n = sc . nextInt (); int result ...
PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY I/P: 5 1 0 2 0 0 O/P: 3 This program explains how many zeros present in the zero PROGRAM: import java . util .*; public class ZeroCount { public static void main ( String args []) { Scanner sc = new Scanner ( System . in ); int iNum = sc . nextInt (); int arr []= new int [ iNum ]; for ( int i = 0 ; i < iNum ; i ++) { arr [ i ]= sc . nextInt (); } int count = 0 ; ...
Sample Input 3 sam 99912222 tom 11122222 harry 12299933 sam edward harry Sample Output sam=99912222 Not found harry=12299933 Explanation We add the following (Key,Value) pairs to our map so it looks like this: We then process each query and print key=value if the queried is found in the map; otherwise, we print Not found . Query 0: sam Sam is one of the keys in our dictionary, so we print sam=99912222 . Query 1: edward Edward is not one of the keys in our dictionary, so we print Not found . Query 2: harry Harry is one of the keys in our dictionary, so we print harry=12299933 . SOLUTION: package H acker R ank_problems . practice_problems ; import java . util .*; import java . io .*; public class TelephoneBook { public static void main ( String [] argh ){ Scanne...
Comments
Post a Comment