CODE BOARD TECHNOLOGIES – Fresher Interview Questions with answers
This blog explains about CODE BOARD TECHNOLOGIES – Fresher Interview Questions with answers . Some of the questions are explained clearly well below :
_______________________________________________________________________________
1. Write java program to count words without inbuilt functions ?
INPUT: code board is best code board is best
OUTPUT: code:2 board:2 is:2 best:2
Length Of The String Without Using Java Built In Length Method :
Java Code With Example
The length of the string is easy to define , it is the number of characters in the string including white spaces .
Java make the things easy as it provides the built in length method for the String class (java.lang.String) which is a final class .
for example :
String demo = ” This is java built in method example “
int length= demo.length();
Java make the things easy as it provides the built in length method for the String class (java.lang.String) which is a final class .
for example :
String demo = ” This is java built in method example “
int length= demo.length();
To use the java built in method to calculate the length of the string .
Then there is also a way to calculate the length of the string
Then there is also a way to calculate the length of the string
You can count characters in two ways.
- Including space
- Excluding space
Below there are 2 programs to count characters in a string, I hope this might help you.
1.Program to count characters in a string including space
- import java.util.Scanner;
- public class Program
- {
- public static void main(String[] args)
- {
- System.out.println(“Enter the String”);
- Scanner scan=new Scanner(System.in);
- String input = scan.nextLine();
- char [] ch = input.toCharArray(); // converts string into character array
- System.out.println(ch.length); // prints the character count including space
- }
- }
2.Program to count characters in a string Excluding space
- import java.util.Scanner;
-
public class Program
-
{
-
public static void main(String[] args)
-
{
-
System.out.println(“Enter the String”);
-
Scanner scan=new Scanner(System.in);
-
String input = scan.nextLine();
-
char [] ch = input.toCharArray();
-
int count=0;
-
for (int i = 0; i < ch.length; i++)
-
{
-
if (ch[i]!=‘ ‘)
-
{
-
count++;
-
}
-
}
-
System.out.println(count++);
-
}
-
}
_______________________________________________________________________________
REFERENCES :
https://www.quora.com/How-do-I-count-characters-in-a-string-in-Java-without-using-charcount