Skip to main content

Posts

Showing posts from March, 2020

How to removed White space in Given String|| Write a program to removed the space by er prince kumar

Write a program to removed all the white space in String ====================================================================== import java.util.*; class  RemovedSpaceFromString { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Input:"); String s=sc.nextLine(); String s1=""; for(int i=0;i<s.length();i++){           if(s.charAt(i)!=' '){              s1=s1+s.charAt(i);   } } s=s1; System.out.println("Output:"+s); System.out.println(); } } Output:
How to print and count number of duplicate Word in the given String. ====================================================================== Codaing Part: How to print and count number of duplicate Word in the given String =============================== //Write a java program to find the Duplicate word and occurens time import java.util.*; class FindDuplicateWOrd  { public static void main(String[] args)  { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); s=s.toLowerCase(); String s1[]=s.split(" ");        //applay the logic    for(int i=0;i<s1.length;i++){   int count=1;           for(int j=i+1;j<s1.length;j++){              if(s1[i].equals(s1[j])){                   count++; s1[j]="o"; } } if(count>1&& s1[i]!="o")   System.out.println(s1[i]);    } } } Output:

How to print the pascal Tringal in a vary the easy way | Print any pattern | Interview Questions

😀If you want to print  pascal Tringal then this  source code for you.😂 import java.util.Scanner; class PascalTringal1  { public static void main(String[] args)  { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<n;i++){            for(int s=0;s<n-i;s++){               System.out.print(" ");     } int val=1; for(int j=0;j<=i;j++){                System.out.print(val+" ");    val=val*(i-j)/(j+1); } System.out.println(); } System.out.println(""); } } Output:

How to Count the characters in String in java || by Er prince Kumar

Write a program to count number of Character in String ====================================================================== import java.util.Scanner; class CountCharacter{    public static void main(String args[]){    Scanner sc=new Scanner(System.in);     String s=sc.nextLine();    int count=0;     for(int i=0;i<s.length();i++){      if(s.charAt(i)!=' ') count++;     }     System.out.println("Number Of Character:"+count);    } } Output ====================================================================

How to count words in given String in java || by Er prince kumar

Write a program to find Number of Word Avilable in givin String ============================================================= import java.util.Scanner; class  FindNumberOfWordAvilable { public static void main(String[] args)  { //Take the String Through the user Scanner sc=new Scanner(System.in); String s=sc.nextLine(); //take the count variable to count number of word int count=0; //Applay the loop To go through the end of the String             for(int i=0;i<s.length();i++){ //Applay the logic to check the Condition           if(((i>0)&&(s.charAt(i)!=' ')&&(s.charAt(i-1)==' '))||       (s.charAt(0)!=' ')&&i==0) count++;          } System.out.println("Count:"+count); } } Output  ======================================================================= =