0% found this document useful (0 votes)
12 views12 pages

Java String and Number Processing Methods

Uploaded by

mahajanvans16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views12 pages

Java String and Number Processing Methods

Uploaded by

mahajanvans16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1. Write main method in Solution class.

In the main method, read a string


and find the count of words starting with a vowel in the string. If no words
are present in the String value then it should print "No String found".

Note:
All search should be case insensitive.

Sample input1:
Everyone should practice and learn to became professional.
Output: 2

Sample input2:
hi guys
Output:
No String found

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Text : ");
String s1 = [Link]();
String[] s2 = [Link](" ");
int vcount = 0;
for(int i=0;i<[Link];i++)
{
char f = s2[i].charAt(0);
if (f=='A' || f=='E' || f=='I' ||f=='O' || f=='U' || f=='a' || f=='e' ||
f=='i' || f=='o' || f=='u')
vcount++;
}
if (vcount>0)
[Link](vcount);
else
[Link]("No String Found");
}
}
Q2. Write main method in Solution [Link] the main method, read a String
value and print the count of lower case characters present in the input
String value. If no lower case characters are present in the String value then
it should print "No lower case characters present" as a String.

Sample input1:
XpLore
Output: 4

Sample input2:
XPLORE
Output: No Lower Case Character Present

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Text : ");
String s1 = [Link]();
int lower = 0;
for(int i=0;i<[Link]();i++){
if([Link]([Link](i)))
lower++;
}
if(lower>0)
[Link](lower);
else
[Link]("No lower case characters present");
}
}
Q3. Write the main method in the Solution [Link] the main method, read
an integer value and print "TRUE" if it contains at least 3 odd digits. Else it
should print "FALSE".
For example, if the value is 123456 and it contains 3 odd digits such as 1,3,5.
So it should print "TRUE". The output should be in the format of sample
output.

Sample input1:
123456
Output: TRUE

Sample input2: 123


Output: FALSE

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Number : ");
int n = [Link]();
int ocount = 0;
while(n>0){
int rem = n%10;
if(rem!=0){
ocount++;
}
n = n/10;
}
if(ocount>3)
[Link]("TRUE");
else
[Link]("FALSE");
}
}
Q4. Write a java program to computer the no of spaces and characters in a
given string.

Input:
hello i am vanshika Mahajan
output:
spaces: 4
characters: 23

import [Link];
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
[Link]("Enter Text : ");
String s1 = [Link]();
int spcount=0;
int chcount=0;

for(int i=0;i<[Link]();i++){
char ch = [Link](i);
if(ch == ' ')
spcount++;
else
chcount++;
}

[Link]("spaces: "+spcount);
[Link]("characters: "+chcount);

}
}
Q5.
Input:
Xplore
ch input:
r
Output:
4

import [Link];
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
[Link]("Enter Text : ");
String s1 = [Link]();
[Link]("Enter Char : ");
char ch = [Link]().charAt(0);
int i = 0;

for(i=0;i<[Link]();i++){
if([Link](i)==ch)
break;
}

[Link]("Position : " +i);

}
}
Q6. Input: 12345
Output: 54321

import [Link];
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
[Link]("Enter a Number : ");
int n = [Link]();
int digit = 0;

while(n!=0){
int rem = n%10;
digit = digit*10 + rem;
n=n/10;
}

[Link](digit);

}
}
Q7. Input array = 1,2,3,4,7
Sum=1+3+7 = 11
Note: 8<sum<50

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[] arr = new int[5];
int sum = 0;

[Link]("Enter Numbers : ");


for(int i=0;i<5;i++){
arr[i] = [Link]();
}

for(int i=0;i<5;i++){
if(arr[i]%2!=0)
sum=sum+arr[i];
}

if(sum>8 && sum<50)


[Link](sum);
else
[Link]("NA");

}
}
Q8. Word = “Hello”
Vowel =2
Consotants = 3

import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Text : ");
String s1 = [Link]();
int vcount = 0;
int ccount = 0;
for(int i=0;i<[Link]();i++){
if ([Link](i)=='A'||[Link](i)=='E'||[Link](i)=='I'||
[Link](i)=='O'||[Link](i)=='U'||[Link](i)=='a'||
[Link](i)=='e'||[Link](i)=='i'||[Link](i)=='o'||[Link](i)=='u')
vcount++;
else
ccount++;
}

[Link](vcount);
[Link](ccount);
}
}

Q9. Longest string


Input: Hello everyone
Output: everyone

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter String");
String s1 = [Link]();
String[] s2 = [Link](" ");
String longest = "";

for(int i=0;i<[Link];i++){
if(s2[i].length() > [Link]())
longest = s2[i];
}

[Link](longest);
}
}

Q10. INPUT: CHNKSC


OUTPUT: CSK

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter String");
String s1 = [Link]();
String rev = "";

for(int i=[Link]()-1;i>=3;i--){
rev += [Link](i);
}

[Link](rev);
}
}

Q11. ALPHANUMERIC STRING


GET SUM OF NUMBERS ONLY THAT TO BE UPTO 15 AND
EQUAL TO 15 AND NOT MORE THAN THAT.

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter String");
String s1 = [Link]();
int sum = 0;

for(int i=0;i<[Link]();i++){
char ch = [Link](i);
if([Link](ch)){
sum = sum+[Link](ch);
}
}

if(sum<=15)
[Link](sum);
else
[Link]("No Digit");
}
}

Q12. Input : Experience


Output : exprinc

import [Link];
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter String");
String s1 = [Link]();

String res = "";

for(int i=0;i<[Link]();i++){
char ch = [Link](i);
if([Link](ch) == -1){
res = res+ch;
}
}

[Link](res);

}
}

You might also like