Computer Science, asked by samharsh, 1 year ago

(1) WAP to print the following string in the following output:
Enter The word to display the pattern : BLUEJ
B
B L
B L U
B L U E
B L U E J

(2) Write a program in Java to accept a string and count the number of vowels in the string Sample Input: Alok Kumar Output: The number of vowels = 4
(3) WAP in Java to accept a word in lower case and replace 'e' with '*' present in the word.
Sample Input :percentage
Output: p*rc*ntag*

Answers

Answered by prakriti27
12
1)class Pattern
{
void main()
{
String s = "BLUEJ"
int n = s.length();
int i, j;
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
System.out.print( s.charAt(i) );
}
System.out.println();
}
}
}

2)import java.util.*
class Vowel
{
void main()
{
Scanner sn = new Sccanner (System.in);
System.out.println("Enter a string");
String s= sn.nextLine();
char ch;
int n, count =0;
n=s.length();
for(i=0; i<n; i++)
{
ch = s.charAt(i)
if ( ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' || ch=='o' || ch=='U' || ch=='u')
{
count++;
}
}
System.out.println("Total number of vowels = " + count);
}
}

3)import java.util.*
class Replace
{
void main()
{
Scanner sn = new Scanner (System.in);
System.out.println("Enter string in lower case");
String s = sn.nextLine();
s=s.toLowerCase();
System.out.println( s.replace(e,*) );
}
}

prakriti27: mark it as the best
Answered by mastermaths55
1

Answer:

Explanation:

1)class Pattern

{

void main()

{

String s = "BLUEJ"

int n = s.length();

int i, j;

for(i=0; i<n; i++)

{

for(j=0; j<=i; j++)

{

System.out.print( s.charAt(i) );

}

System.out.println();

}

}

}

2)import java.util.*

class Vowel

{

void main()

{

Scanner sn = new Sccanner (System.in);

System.out.println("Enter a string");

String s= sn.nextLine();

char ch;

int n, count =0;

n=s.length();

for(i=0; i<n; i++)

{

ch = s.charAt(i)

if ( ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' || ch=='o' || ch=='U' || ch=='u')

{

count++;

}

}

System.out.println("Total number of vowels = " + count);

}

}

3)import java.util.*

class Replace

{

void main()

{

Scanner sn = new Scanner (System.in);

System.out.println("Enter string in lower case");

String s = sn.nextLine();

s=s.toLowerCase();

System.out.println( s.replace(e,*) );

}

}

Similar questions