Posts

Showing posts with the label java practice programs

Check if String contains only Digit's - Java 2024 - Technical Interview

 Check String contains only Digit's           Get the input from the user using Scanner class. Then create a method to check the following condition. 1. Check if the string is null or empty, if it is directly return false. 2. Iterate the String using for loop inside the for loop, use the if for condition checking. 3. Condition is check the Digit's only, for this use the Character Wrapper class, in that we have isDigit() method to check the Digit's. 4. This method will return true or false based on it is Digit's or not. Code : package com.dinatechy.challange; import java.util.Scanner; public class CheckDigitsOnly { public static void main(String[] args ) { //To check if the String contains only Digit's Scanner scan = new Scanner(System. in ); String data = scan .next(); scan .close(); boolean isDigits = checkDigits ( data ); System. out .println( isDigits ? "Yes it is" : "No it's not" ); } privat...

Java Program Question - MNC - Technical Interview

                Here we are going to see a very Interesting and Complicated Java Programming Questions, which is asking in literally all MNC's Technical Interview's Input : Array -- { 5,1,8,-5,-1,6,2,-2,45,-55,-9,-89,9 } Output :  Array -- { -89 -55 -9 9 -5 5 -2 2 -1 1 6 8 45 } Program :  package com.array; public class SortingArray { public static void main ( String [] args ) { int [] arr = { 5 , 1 , 8 ,- 5 ,- 1 , 6 , 2 ,- 2 , 45 ,- 55 ,- 9 ,- 89 , 9 }; for ( int a : arr ) { System . out . print ( a + " " ); } System . out . println (); for ( int i = 0 ; i < arr . length ; i ++) { for ( int j = i ; j < arr . length ; j ++) { if ( arr [ i ]> arr [ j ]) { int temp = arr [ i ]; arr [ i ] = arr [ j ]; arr [ j ] = temp ; } } } for ( int i = 0 ; i < arr . length ; i ++) {            ...