Posts

Showing posts with the label java tutorial

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...

Control Statement in Java - Flow Chart - Professional Programming

Control Statement :                 If we want to control our program based on some condition, their is the place we must know the concept of Control Statement.               Naturally all the Control Statement executes based on true or false .              Their are various types of control statements,  Types : Decision Making Statement Iteration or Looping statements Jump Statement Decis ion Making Statement :                Decision making statements in Java refer to those statements that allow the programmer to specify decisions or conditional execution flows in their code. The decision making statements in Java are primarily composed are .                Types :  if if-else else-if nested if-else switch     if Statement :        ...