0% found this document useful (0 votes)
10 views6 pages

Amol String Assigenment 18 04 2022

Uploaded by

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

Amol String Assigenment 18 04 2022

Uploaded by

Pratik Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME:AMOL RAJKUMAR JADHAV

DATE:18-04-2022
Asssigenment-String-First
==============================================

1.initilised a string by both literal and by new and print it

ProGram-
package String_Method;

public class Q1 {
public static void main(String[] args) {
String s = "Amol";
System.out.println(s);
String s1 = new String("Amol");
System.out.println(s1);
}
}

OutPut:
Amol
Amol
===================================================

2.enter a string by user and print it

ProGram--
package String_Method;

import java.util.Scanner;

public class Q2
{
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
System.out.println("Enter Any String");
String s=x.nextLine();
System.out.println(s);

}
}

OutPut:
Enter Any String
Amo rajkumar Jadhav
Amo rajkumar Jadhav
================================================

3.enter a string by user and find its length

ProGram=

package String_Method;

import java.util.Scanner;

public class Q3 {
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.println("Enter any String");
String s = x.nextLine();
System.out.println("length="+s.length());
}
}

OutPut:
Enter any String
Rajkumar
length=8
===============================================

4.enter a string by user and print its 1st and last character

ProGram=
package String_Method;

import java.util.Scanner;

public class Q4
{
public static void main(String[] args)
{
Scanner x=new Scanner(System.in);
System.out.println("Enter Any String");
String s=x.nextLine();
System.out.println("First="+s.charAt(0));
System.out.println("Length="+s.charAt(s.length()-1));

}
}

OutPut:
Enter Any String
Amol
First=A
Length=l
==================================================

5.enter a string by user and print it in verticle form

ProGram==
package String_Method;

import java.util.Scanner;

public class Q5
{
public static void main(String[] args)
{
Scanner x=new Scanner(System.in);
System.out.println("Enter String Charecter");
String s=x.nextLine();
int i;
for(i=0;i<s.length();i++)
{
System.out.println(s.charAt(i));
}

}
}

OutPut:
Enter String Charecter
Rajkumar
R
a
j
k
u
m
a
r
=====================================================

6.enter a string by user and search particular element are present or not

ProGram=
package String_Method;

import java.util.Scanner;

public class Q6 {
public static void main(String[] args) {

Scanner x = new Scanner(System.in);


System.out.println("Enter String");
String s=x.nextLine();
System.out.println("Searching Charecter");
char n=x.next().charAt(0);
int i,c=0;
for(i=0;i<s.length();i++)
{
if(s.charAt(i)==n)
{
c++;
}
}
if(c>0)
{
System.out.println("found="+c);

}
else
{
System.out.println("Not Found");

}
}

OutPUt:
Enter String
my name is Amol
Searching Charecter
a
found=1
=================================================

7.Wap enter a string and print the character present at even position.

ProGram==
package String_Method;

import java.util.Scanner;

public class Q7
{
public static void main(String[] args)
{
Scanner x=new Scanner(System.in);
System.out.println("Enter a String");
String s=x.nextLine();
System.out.println("Index\ncharecter");
int i;
for(i=0;i<s.length();i++)
{
if(i%2==0)
{
System.out.println(i+" "+s.charAt(i));
}
}

}
}

OutPut:
Enter a String
Rameshwar
Index
charecter
0 R
2 m
4 s
6 w
8 r
==================================================

8.Wap enter a string and print the character present at odd position.

ProGram=

package String_Method;

import java.util.Scanner;

public class Q8
{
public static void main(String[] args)
{
Scanner x=new Scanner(System.in);
System.out.println("Enter a String");
String s=x.nextLine();
System.out.println("Index\ncharecter");
int i;
for(i=0;i<s.length();i++)
{
if(i%2!=0)
{
System.out.println(i+" "+s.charAt(i));
}
}

}
}
OutPut:
Enter a String
Rameshwar
Index
charecter
1 a
3 e
5 h
7 a
=======================================================

9.enter a string by user and search particular character and print its no

ProGram=
package String_Method;

import java.util.Scanner;

public class Q9
{
public static void main(String[] args)
{
Scanner x=new Scanner(System.in);
System.out.println("Enter Any String");
String s=x.nextLine();
System.out.println("Search any Number");
char n=x.next().charAt(0);
System.out.println(" charecter idex Number");
int i,c=0;
for(i=0;i<s.length();i++)
{
if(s.charAt(i)==n)
{
c++;
System.out.println(i+" "+s.charAt(i));
}
}

}
}

OutPut:
Enter Any String
hathi mera sathi
Search any Number
a
charecter idex Number
1 a
9 a
12 a
================================================
10.enter a string and count the no of vowel and consonent.

package String_Method;

import java.util.Scanner;

public class Vowel_Consonant


{
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
System.out.println("Enter any string");
String s=x.nextLine();
int i,Vcount=0,Ccount=0;
for(i=0;i<s.length();i++)
{
if (s.charAt(i) == 'a' || s.charAt(i) == 'e' || s.charAt(i) == 'i' ||
s.charAt(i) == 'o' || s.charAt(i) == 'u' || s.charAt(i) == 'A' || s.charAt(i) ==
'E' || s.charAt(i) == 'I' || s.charAt(i) == 'O' || s.charAt(i) == 'U') {
Vcount++;
} else {
Ccount++;
}
}
System.out.println("Vowel="+Vcount);
System.out.println("ConsoNant="+Ccount);

}
}

OutPut:
Enter any string
mera name joker
Vowel=6
ConsoNant=9
==================================================

You might also like