0% found this document useful (0 votes)
7 views

Document 1

Uploaded by

dhimanadamya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Document 1

Uploaded by

dhimanadamya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 108

write a program in java to input A word in

uppercase and check the position for First


occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3)
Copilot
Sure! Let's break down the task into steps and wr
ite a Java program to perform the required operat
ions. We'll input a word in uppercase, check the p
osition of the first occurring vowel, and perform t
he specified operations.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
5.Output the results.
6.End
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
}

if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
}

scanner.close();
}

public static int findFirstVowelPosition(String


word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Explanation:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y'.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c'.
8.Print the results.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy
Word contains a vowel: APPLEc

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


(No output since there is no vowel in "SKY")
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance2
1github.com2github.com
You
write a program in java to input A word in
uppercase and check the position for First
occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3) Word which
do not contain a vowel (4) Write the steps
algorithm variable description and a print of
terminal window.
Copilot
Sure! Let's break down the task and create a Java
program along with the algorithm, variable descri
ption, and an example of the terminal output.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
 If the word does not contain a vowel, out
put the original word.
5.Output the results.
6.End
Variable Description:
 word: The input word provided by the user.
 vowelPosition: The position of the first occurri
ng vowel in the input word.
 part1: The substring from the position of the
vowel till the end of the word.
 part2: The substring from the beginning of th
e word till the position of the vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
} else if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
} else {
// Word does not contain a vowel
System.out.println("Word does not
contain a vowel: " + word);
}

scanner.close();
}
public static int findFirstVowelPosition(String
word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y' and output the
result.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c', then output the result.
8.Check if the word does not contain a vowel. I
f so, output the original word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


Word does not contain a vowel: SKY
This should give you a complete understanding of
how to achieve the required operations based on
the input word. Let me know if you have any que
stions or need further assistance2
1github.com2github.com
You
Write a programme in Java to input a sentence
from the user and count the number of times the
word an and and are present in the sentence.
Write the steps algorithm and variable
description for the programme. Also print the
terminal window
Copilot
Sure! Let's create a Java program to input a sente
nce from the user and count the number of times
the words "an" and "and" are present in the sent
ence. I'll also provide the algorithm, variable desc
riptions, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using a space
as the delimiter.
5.Initialize counters for "an" and "and".
6.Iterate through the list of words.
 Increment the respective counter if the
word is "an" or "and".
7.Output the counts of "an" and "and".
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 anCount: Counter for the occurrences of the
word "an".
 andCount: Counter for the occurrences of the
word "and".
Java Program:
java
Copy
import java.util.Scanner;

public class WordCount {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counters
int anCount = 0;
int andCount = 0;

// Iterate through the words


for (String word : words) {
if (word.equals("an")) {
anCount++;
} else if (word.equals("and")) {
andCount++;
}
}

// Output the results


System.out.println("Number of times 'an' is
present: " + anCount);
System.out.println("Number of times 'and' is
present: " + andCount);
scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a WordCount class with a main meth
od.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize counters anCount and andCount to
zero.
8.Iterate through the array of words:
 Increment anCount if the word is "an".
 Increment andCount if the word is "and"
.
9.Output the counts of "an" and "and".
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple and an orange are on
the table.
Number of times 'an' is present: 2
Number of times 'and' is present: 1
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java Using the scanner
class to modify a word by bringing all the vowels
in the world at the begin followed by consonants.
re concatenated with n (2) Write the steps
algorithm and the variable description of the
programme Also print the terminal window
Copilot
Let's create a Java program that rearranges a wor
d by bringing all the vowels to the beginning, foll
owed by the consonants, and then concatenates
"n" at the end. I'll also provide the algorithm, vari
able description, and an example of the terminal
output.
Algorithm:
1.Start
2.Accept a word input from the user.
3.Initialize two empty strings: one for vowels
and one for consonants.
4.Iterate through each character in the word.
 Check if the character is a vowel. If so, a
dd it to the vowels string.
 If the character is a consonant, add it to t
he consonants string.
5.Concatenate the vowels string with the cons
onants string and add "n" at the end.
6.Output the modified word.
7.End
Variable Description:
 word: The input word provided by the user.
 vowels: A string to store all the vowels found
in the word.
 consonants: A string to store all the consonan
ts found in the word.
 modifiedWord: The final modified word after r
earranging and concatenating "n".
Java Program:
java
Copy
import java.util.Scanner;

public class VowelConsonantModification {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word: ");
String word = scanner.nextLine();

// Initialize empty strings for vowels and


consonants
String vowels = "";
String consonants = "";

// Iterate through each character in the word


for (char ch : word.toCharArray()) {
if (isVowel(ch)) {
vowels += ch;
} else {
consonants += ch;
}
}
// Concatenate vowels and consonants, then
add "n"
String modifiedWord = vowels + consonants
+ "n";

// Output the modified word


System.out.println("Modified word: " +
modifiedWord);

scanner.close();
}

public static boolean isVowel(char ch) {


ch = Character.toLowerCase(ch); // Make the
check case-insensitive
return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelConsonantModification class
with a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word and read th
e input.
5.Initialize two empty strings, vowels and con
sonants, to store vowels and consonants sep
arately.
6.Iterate through each character in the word:
 Check if the character is a vowel using th
e isVowel method. If so, add it to the vow
els string.
 If the character is a consonant, add it to t
he consonants string.
7.Concatenate the vowels string with the cons
onants string and add "n" at the end to form
modifiedWord.
8.Output the modified word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word: HELLO
Modified word: EOHLn
Enter a word: JAVA
Modified word: AJAAn

Enter a word: COMPUTER


Modified word: OUECMPTRn
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java using scanner class to
check whether a sentence has a word beginning
with a capital letter or not Also write the steps
algorithm variable description and print the
terminal window
Copilot
Absolutely! Let's write a Java program that check
s if a sentence contains a word beginning with a
capital letter. I'll provide the algorithm, variable d
escription, and an example of the terminal output
.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Split the sentence into words using space as
a delimiter.
4.Initialize a flag to check for words starting w
ith a capital letter.
5.Iterate through the words:
 Check if the first character of each word i
s a capital letter.
 Set the flag if a capital letter is found.
6.Output the result based on the flag.
7.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 hasCapitalWord: A boolean flag to indicate if t
here is a word starting with a capital letter.
Java Program:
java
Copy
import java.util.Scanner;

public class CapitalLetterCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Accept user input
System.out.print("Enter a sentence: ");
String sentence = scanner.nextLine();

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize flag
boolean hasCapitalWord = false;

// Iterate through the words


for (String word : words) {
if
(Character.isUpperCase(word.charAt(0))) {
hasCapitalWord = true;
break;
}
}

// Output the result


if (hasCapitalWord) {
System.out.println("The sentence
contains a word beginning with a capital letter.");
} else {
System.out.println("The sentence does
not contain a word beginning with a capital
letter.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a CapitalLetterCheck class with a mai
n method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Split the sentence into words using the split
method with space as the delimiter.
6.Initialize a boolean flag hasCapitalWord to f
alse.
7.Iterate through the array of words:
 Check if the first character of each word i
s a capital letter using Character.isUpper
Case method.
 Set hasCapitalWord to true and break the
loop if a capital letter is found.
8.Output the result based on the value of hasC
apitalWord.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a sentence: This is a Test sentence.
The sentence contains a word beginning with a
capital letter.

Enter a sentence: this is a test sentence.


The sentence does not contain a word beginning
with a capital letter.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
write to programme in Java using scanner class
to accept a sentence and calculate the frequency
of word that begin with a Vowel Also write the
steps algorithm and variable description for the
programme and print the terminal window.
Copilot
Sure! Let's create a Java program that accepts a
sentence from the user, calculates the frequency
of words that begin with a vowel, and prints the r
esult. I'll provide the algorithm, variable descripti
on, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using space as
a delimiter.
5.Initialize a counter for words that begin with
a vowel.
6.Iterate through the list of words.
 Check if the first character of each word i
s a vowel.
 Increment the counter if a word begins
with a vowel.
7.Output the frequency of words that begin wi
th a vowel.
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 vowelCount: Counter for the frequency of wor
ds that begin with a vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelWordFrequency {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counter
int vowelCount = 0;

// Iterate through the words


for (String word : words) {
if (word.length() > 0 &&
isVowel(word.charAt(0))) {
vowelCount++;
}
}

// Output the frequency of words that begin


with a vowel
System.out.println("Number of words
beginning with a vowel: " + vowelCount);

scanner.close();
}

public static boolean isVowel(char ch) {


return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelWordFrequency class with a
main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case-insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize a counter vowelCount to zero.
8.Iterate through the array of words:
 Check if the word length is greater than
0 and if the first character of each word is
a vowel using the isVowel method.
 Increment vowelCount if a word begins
with a vowel.
9.Output the frequency of words that begin wi
th a vowel.
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple a day keeps the
doctor away.
Number of words beginning with a vowel: 4

Enter a sentence: This is an example sentence.


Number of words beginning with a vowel: 2

Enter a sentence: Hello World!


Number of words beginning with a vowel: 0
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java to check if a given
number is in Armstrong number or not. Also write
the variable description steps and algorithm for
the programme and print the terminal window.
Copilot
Sure! Let's create a Java program that checks if a
given number is an Armstrong number. I'll also pr
ovide the algorithm, variable descriptions, and an
example of the terminal output.
Algorithm:
1.Start
2.Accept a number input from the user.
3.Initialize variables to store the original num
ber, a copy of the number, and the result.
4.Calculate the number of digits in the numbe
r.
5.Iterate through each digit of the number:
 Extract the last digit.
 Raise the digit to the power of the numb
er of digits and add it to the result.
 Remove the last digit from the number.
6.Compare the result with the original number
to check if it's an Armstrong number.
7.Output the result.
8.End
Variable Description:
 number: The input number provided by the u
ser.
 originalNumber: A copy of the original numbe
r to compare with the result.
 n: The number of digits in the input number.
 result: The sum of each digit raised to the po
wer of n.
 temp: A temporary variable to store the curre
nt digit being processed.
Java Program:
java
Copy
import java.util.Scanner;

public class ArmstrongNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a number: ");
int number = scanner.nextInt();

// Initialize variables
int originalNumber = number;
int result = 0;
int n = String.valueOf(number).length();

// Check if the number is an Armstrong


number
while (number != 0) {
int temp = number % 10;
result += Math.pow(temp, n);
number /= 10;
}

// Output the result


if (result == originalNumber) {
System.out.println(originalNumber + " is
an Armstrong number.");
} else {
System.out.println(originalNumber + " is
not an Armstrong number.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create an ArmstrongNumberCheck class wit
h a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a number and read
the input.
5.Initialize variables originalNumber to store t
he original number, result to store the sum of
digits raised to the power of the number of di
gits, and n to store the number of digits in th
e input number.
6.Use a while loop to process each digit of the
number:
 Extract the last digit using the modulus
operator %.
 Raise the digit to the power of n using M
ath.pow and add it to result.
 Remove the last digit from the number u
sing integer division /.
7.Compare result with originalNumber. If they
are equal, the number is an Armstrong numb
er; otherwise, it is not.
8.Output the result.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a number: 153
153 is an Armstrong number.

Enter a number: 123


123 is not an Armstrong number.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme to cheque if the given
number is a perfect number or not. Also write the
terminal window and steps variable description
and algorithm for programme
Copilot
Sure! Let's create a Java program that checks if a
given number is a perfect number. I'll also provid
e the algorithm, variable description, and an exa
mple of the terminal output.
Algorithm:
1.Start
2.Accept a number input from the user.
3.Initialize a variable to store the sum of divis
ors.
4.Iterate through numbers from 1 to half of th
e given number.
 Check if the current number is a divisor o
f the given number.
 Add the divisor to the sum of divisors.
5.Compare the sum of divisors with the origina
l number to check if it's a perfect number.
6.Output the result.
7.End
Variable Description:
 number: The input number provided by the u
ser.
 sumOfDivisors: The sum of all divisors of the i
nput number.
 i: The current number being checked as a divi
sor.
Java Program:
java
Copy
import java.util.Scanner;

public class PerfectNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a number: ");
int number = scanner.nextInt();

// Initialize sum of divisors


int sumOfDivisors = 0;
// Check divisors and calculate sum
for (int i = 1; i <= number / 2; i++) {
if (number % i == 0) {
sumOfDivisors += i;
}
}

// Check if the number is a perfect number


if (sumOfDivisors == number) {
System.out.println(number + " is a
perfect number.");
} else {
System.out.println(number + " is not a
perfect number.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a PerfectNumberCheck class with a m
ain method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a number and read
the input.
5.Initialize a variable sumOfDivisors to store t
he sum of all divisors of the input number.
6.Use a for loop to check for divisors from 1 to
half of the input number:
 Check if the current number is a divisor o
f the input number using the modulus op
erator %.
 Add the divisor to sumOfDivisors if it divi
des the input number.
7.Compare sumOfDivisors with the input num
ber. If they are equal, the number is a perfect
number; otherwise, it is not.
8.Output the result.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a number: 28
28 is a perfect number.
Enter a number: 10
10 is not a perfect number.
write a program in java to input A word in
uppercase and check the position for First
occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3)
Copilot
Sure! Let's break down the task into steps and wr
ite a Java program to perform the required operat
ions. We'll input a word in uppercase, check the p
osition of the first occurring vowel, and perform t
he specified operations.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
5.Output the results.
6.End
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
}

if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
}

scanner.close();
}

public static int findFirstVowelPosition(String


word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Explanation:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y'.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c'.
8.Print the results.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy
Word contains a vowel: APPLEc

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


(No output since there is no vowel in "SKY")
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance2
1github.com2github.com
You
write a program in java to input A word in
uppercase and check the position for First
occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3) Word which
do not contain a vowel (4) Write the steps
algorithm variable description and a print of
terminal window.
Copilot
Sure! Let's break down the task and create a Java
program along with the algorithm, variable descri
ption, and an example of the terminal output.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
 If the word does not contain a vowel, out
put the original word.
5.Output the results.
6.End
Variable Description:
 word: The input word provided by the user.
 vowelPosition: The position of the first occurri
ng vowel in the input word.
 part1: The substring from the position of the
vowel till the end of the word.
 part2: The substring from the beginning of th
e word till the position of the vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
} else if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
} else {
// Word does not contain a vowel
System.out.println("Word does not
contain a vowel: " + word);
}

scanner.close();
}
public static int findFirstVowelPosition(String
word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y' and output the
result.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c', then output the result.
8.Check if the word does not contain a vowel. I
f so, output the original word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


Word does not contain a vowel: SKY
This should give you a complete understanding of
how to achieve the required operations based on
the input word. Let me know if you have any que
stions or need further assistance2
1github.com2github.com
You
Write a programme in Java to input a sentence
from the user and count the number of times the
word an and and are present in the sentence.
Write the steps algorithm and variable
description for the programme. Also print the
terminal window
Copilot
Sure! Let's create a Java program to input a sente
nce from the user and count the number of times
the words "an" and "and" are present in the sent
ence. I'll also provide the algorithm, variable desc
riptions, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using a space
as the delimiter.
5.Initialize counters for "an" and "and".
6.Iterate through the list of words.
 Increment the respective counter if the
word is "an" or "and".
7.Output the counts of "an" and "and".
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 anCount: Counter for the occurrences of the
word "an".
 andCount: Counter for the occurrences of the
word "and".
Java Program:
java
Copy
import java.util.Scanner;

public class WordCount {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counters
int anCount = 0;
int andCount = 0;

// Iterate through the words


for (String word : words) {
if (word.equals("an")) {
anCount++;
} else if (word.equals("and")) {
andCount++;
}
}

// Output the results


System.out.println("Number of times 'an' is
present: " + anCount);
System.out.println("Number of times 'and' is
present: " + andCount);
scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a WordCount class with a main meth
od.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize counters anCount and andCount to
zero.
8.Iterate through the array of words:
 Increment anCount if the word is "an".
 Increment andCount if the word is "and"
.
9.Output the counts of "an" and "and".
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple and an orange are on
the table.
Number of times 'an' is present: 2
Number of times 'and' is present: 1
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java Using the scanner
class to modify a word by bringing all the vowels
in the world at the begin followed by consonants.
re concatenated with n (2) Write the steps
algorithm and the variable description of the
programme Also print the terminal window
Copilot
Let's create a Java program that rearranges a wor
d by bringing all the vowels to the beginning, foll
owed by the consonants, and then concatenates
"n" at the end. I'll also provide the algorithm, vari
able description, and an example of the terminal
output.
Algorithm:
1.Start
2.Accept a word input from the user.
3.Initialize two empty strings: one for vowels
and one for consonants.
4.Iterate through each character in the word.
 Check if the character is a vowel. If so, a
dd it to the vowels string.
 If the character is a consonant, add it to t
he consonants string.
5.Concatenate the vowels string with the cons
onants string and add "n" at the end.
6.Output the modified word.
7.End
Variable Description:
 word: The input word provided by the user.
 vowels: A string to store all the vowels found
in the word.
 consonants: A string to store all the consonan
ts found in the word.
 modifiedWord: The final modified word after r
earranging and concatenating "n".
Java Program:
java
Copy
import java.util.Scanner;

public class VowelConsonantModification {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word: ");
String word = scanner.nextLine();

// Initialize empty strings for vowels and


consonants
String vowels = "";
String consonants = "";

// Iterate through each character in the word


for (char ch : word.toCharArray()) {
if (isVowel(ch)) {
vowels += ch;
} else {
consonants += ch;
}
}
// Concatenate vowels and consonants, then
add "n"
String modifiedWord = vowels + consonants
+ "n";

// Output the modified word


System.out.println("Modified word: " +
modifiedWord);

scanner.close();
}

public static boolean isVowel(char ch) {


ch = Character.toLowerCase(ch); // Make the
check case-insensitive
return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelConsonantModification class
with a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word and read th
e input.
5.Initialize two empty strings, vowels and con
sonants, to store vowels and consonants sep
arately.
6.Iterate through each character in the word:
 Check if the character is a vowel using th
e isVowel method. If so, add it to the vow
els string.
 If the character is a consonant, add it to t
he consonants string.
7.Concatenate the vowels string with the cons
onants string and add "n" at the end to form
modifiedWord.
8.Output the modified word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word: HELLO
Modified word: EOHLn
Enter a word: JAVA
Modified word: AJAAn

Enter a word: COMPUTER


Modified word: OUECMPTRn
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java using scanner class to
check whether a sentence has a word beginning
with a capital letter or not Also write the steps
algorithm variable description and print the
terminal window
Copilot
Absolutely! Let's write a Java program that check
s if a sentence contains a word beginning with a
capital letter. I'll provide the algorithm, variable d
escription, and an example of the terminal output
.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Split the sentence into words using space as
a delimiter.
4.Initialize a flag to check for words starting w
ith a capital letter.
5.Iterate through the words:
 Check if the first character of each word i
s a capital letter.
 Set the flag if a capital letter is found.
6.Output the result based on the flag.
7.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 hasCapitalWord: A boolean flag to indicate if t
here is a word starting with a capital letter.
Java Program:
java
Copy
import java.util.Scanner;

public class CapitalLetterCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Accept user input
System.out.print("Enter a sentence: ");
String sentence = scanner.nextLine();

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize flag
boolean hasCapitalWord = false;

// Iterate through the words


for (String word : words) {
if
(Character.isUpperCase(word.charAt(0))) {
hasCapitalWord = true;
break;
}
}

// Output the result


if (hasCapitalWord) {
System.out.println("The sentence
contains a word beginning with a capital letter.");
} else {
System.out.println("The sentence does
not contain a word beginning with a capital
letter.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a CapitalLetterCheck class with a mai
n method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Split the sentence into words using the split
method with space as the delimiter.
6.Initialize a boolean flag hasCapitalWord to f
alse.
7.Iterate through the array of words:
 Check if the first character of each word i
s a capital letter using Character.isUpper
Case method.
 Set hasCapitalWord to true and break the
loop if a capital letter is found.
8.Output the result based on the value of hasC
apitalWord.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a sentence: This is a Test sentence.
The sentence contains a word beginning with a
capital letter.

Enter a sentence: this is a test sentence.


The sentence does not contain a word beginning
with a capital letter.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
write to programme in Java using scanner class
to accept a sentence and calculate the frequency
of word that begin with a Vowel Also write the
steps algorithm and variable description for the
programme and print the terminal window.
Copilot
Sure! Let's create a Java program that accepts a
sentence from the user, calculates the frequency
of words that begin with a vowel, and prints the r
esult. I'll provide the algorithm, variable descripti
on, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using space as
a delimiter.
5.Initialize a counter for words that begin with
a vowel.
6.Iterate through the list of words.
 Check if the first character of each word i
s a vowel.
 Increment the counter if a word begins
with a vowel.
7.Output the frequency of words that begin wi
th a vowel.
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 vowelCount: Counter for the frequency of wor
ds that begin with a vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelWordFrequency {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counter
int vowelCount = 0;

// Iterate through the words


for (String word : words) {
if (word.length() > 0 &&
isVowel(word.charAt(0))) {
vowelCount++;
}
}

// Output the frequency of words that begin


with a vowel
System.out.println("Number of words
beginning with a vowel: " + vowelCount);

scanner.close();
}

public static boolean isVowel(char ch) {


return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelWordFrequency class with a
main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case-insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize a counter vowelCount to zero.
8.Iterate through the array of words:
 Check if the word length is greater than
0 and if the first character of each word is
a vowel using the isVowel method.
 Increment vowelCount if a word begins
with a vowel.
9.Output the frequency of words that begin wi
th a vowel.
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple a day keeps the
doctor away.
Number of words beginning with a vowel: 4

Enter a sentence: This is an example sentence.


Number of words beginning with a vowel: 2

Enter a sentence: Hello World!


Number of words beginning with a vowel: 0
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java to check if a given
number is in Armstrong number or not. Also write
the variable description steps and algorithm for
the programme and print the terminal window.
Copilot
Sure! Let's create a Java program that checks if a
given number is an Armstrong number. I'll also pr
ovide the algorithm, variable descriptions, and an
example of the terminal output.
Algorithm:
1.Start
2.Accept a number input from the user.
3.Initialize variables to store the original num
ber, a copy of the number, and the result.
4.Calculate the number of digits in the numbe
r.
5.Iterate through each digit of the number:
 Extract the last digit.
 Raise the digit to the power of the numb
er of digits and add it to the result.
 Remove the last digit from the number.
6.Compare the result with the original number
to check if it's an Armstrong number.
7.Output the result.
8.End
Variable Description:
 number: The input number provided by the u
ser.
 originalNumber: A copy of the original numbe
r to compare with the result.
 n: The number of digits in the input number.
 result: The sum of each digit raised to the po
wer of n.
 temp: A temporary variable to store the curre
nt digit being processed.
Java Program:
java
Copy
import java.util.Scanner;

public class ArmstrongNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a number: ");
int number = scanner.nextInt();

// Initialize variables
int originalNumber = number;
int result = 0;
int n = String.valueOf(number).length();

// Check if the number is an Armstrong


number
while (number != 0) {
int temp = number % 10;
result += Math.pow(temp, n);
number /= 10;
}

// Output the result


if (result == originalNumber) {
System.out.println(originalNumber + " is
an Armstrong number.");
} else {
System.out.println(originalNumber + " is
not an Armstrong number.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create an ArmstrongNumberCheck class wit
h a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a number and read
the input.
5.Initialize variables originalNumber to store t
he original number, result to store the sum of
digits raised to the power of the number of di
gits, and n to store the number of digits in th
e input number.
6.Use a while loop to process each digit of the
number:
 Extract the last digit using the modulus
operator %.
 Raise the digit to the power of n using M
ath.pow and add it to result.
 Remove the last digit from the number u
sing integer division /.
7.Compare result with originalNumber. If they
are equal, the number is an Armstrong numb
er; otherwise, it is not.
8.Output the result.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a number: 153
153 is an Armstrong number.

Enter a number: 123


123 is not an Armstrong number.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme to cheque if the given
number is a perfect number or not. Also write the
terminal window and steps variable description
and algorithm for programme
Copilot
Sure! Let's create a Java program that checks if a
given number is a perfect number. I'll also provid
e the algorithm, variable description, and an exa
mple of the terminal output.
Algorithm:
1.Start
2.Accept a number input from the user.
3.Initialize a variable to store the sum of divis
ors.
4.Iterate through numbers from 1 to half of th
e given number.
 Check if the current number is a divisor o
f the given number.
 Add the divisor to the sum of divisors.
5.Compare the sum of divisors with the origina
l number to check if it's a perfect number.
6.Output the result.
7.End
Variable Description:
 number: The input number provided by the u
ser.
 sumOfDivisors: The sum of all divisors of the i
nput number.
 i: The current number being checked as a divi
sor.
Java Program:
java
Copy
import java.util.Scanner;

public class PerfectNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a number: ");
int number = scanner.nextInt();

// Initialize sum of divisors


int sumOfDivisors = 0;
// Check divisors and calculate sum
for (int i = 1; i <= number / 2; i++) {
if (number % i == 0) {
sumOfDivisors += i;
}
}

// Check if the number is a perfect number


if (sumOfDivisors == number) {
System.out.println(number + " is a
perfect number.");
} else {
System.out.println(number + " is not a
perfect number.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a PerfectNumberCheck class with a m
ain method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a number and read
the input.
5.Initialize a variable sumOfDivisors to store t
he sum of all divisors of the input number.
6.Use a for loop to check for divisors from 1 to
half of the input number:
 Check if the current number is a divisor o
f the input number using the modulus op
erator %.
 Add the divisor to sumOfDivisors if it divi
des the input number.
7.Compare sumOfDivisors with the input num
ber. If they are equal, the number is a perfect
number; otherwise, it is not.
8.Output the result.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a number: 28
28 is a perfect number.
Enter a number: 10
10 is not a perfect number.
write a program in java to input A word in
uppercase and check the position for First
occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3)
Copilot
Sure! Let's break down the task into steps and wr
ite a Java program to perform the required operat
ions. We'll input a word in uppercase, check the p
osition of the first occurring vowel, and perform t
he specified operations.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
5.Output the results.
6.End
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
}

if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
}

scanner.close();
}

public static int findFirstVowelPosition(String


word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Explanation:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y'.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c'.
8.Print the results.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy
Word contains a vowel: APPLEc

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


(No output since there is no vowel in "SKY")
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance2
1github.com2github.com
You
write a program in java to input A word in
uppercase and check the position for First
occuring vowel and perform following operations
(1) Word that begins with a Vowel and is
concatinated with y (2) Word that contains a
vowel. In between should have first part from the
position of the vowel till the end Followed by the
part of string from the beginning till the position
of the vowel is Concatenated by c (3) Word which
do not contain a vowel (4) Write the steps
algorithm variable description and a print of
terminal window.
Copilot
Sure! Let's break down the task and create a Java
program along with the algorithm, variable descri
ption, and an example of the terminal output.
Algorithm:
1.Start
2.Accept input from the user.
3.Find the position of the first occurring vowel i
n the input word.
4.Perform the following operations:
 If the word begins with a vowel, concaten
ate it with 'y'.
 If the word contains a vowel, create a ne
w word by concatenating the part from th
e vowel to the end followed by the part fr
om the beginning to the position of the v
owel and add 'c'.
 If the word does not contain a vowel, out
put the original word.
5.Output the results.
6.End
Variable Description:
 word: The input word provided by the user.
 vowelPosition: The position of the first occurri
ng vowel in the input word.
 part1: The substring from the position of the
vowel till the end of the word.
 part2: The substring from the beginning of th
e word till the position of the vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelOperations {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word in
uppercase: ");
String word = scanner.nextLine();

// Find the position of the first occurring


vowel
int vowelPosition =
findFirstVowelPosition(word);

// Perform the required operations


if (vowelPosition == 0) {
// Word that begins with a vowel
System.out.println("Word begins with a
vowel: " + word + "y");
} else if (vowelPosition != -1) {
// Word contains a vowel
String part1 =
word.substring(vowelPosition);
String part2 = word.substring(0,
vowelPosition);
System.out.println("Word contains a
vowel: " + part1 + part2 + "c");
} else {
// Word does not contain a vowel
System.out.println("Word does not
contain a vowel: " + word);
}

scanner.close();
}
public static int findFirstVowelPosition(String
word) {
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch
== 'O' || ch == 'U') {
return i;
}
}
return -1; // No vowel found
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelOperations class with a main
method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word in uppercas
e and read the input.
5.Find the position of the first occurring vowel
using the findFirstVowelPosition method.
6.Check if the word begins with a vowel. If so,
concatenate the word with 'y' and output the
result.
7.Check if the word contains a vowel. If so, cre
ate a new word by concatenating the part fro
m the vowel to the end followed by the part f
rom the beginning to the position of the vowe
l and add 'c', then output the result.
8.Check if the word does not contain a vowel. I
f so, output the original word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word in uppercase: APPLE
Word begins with a vowel: APPLEy

Enter a word in uppercase: HELLO


Word contains a vowel: ELLOHc

Enter a word in uppercase: SKY


Word does not contain a vowel: SKY
This should give you a complete understanding of
how to achieve the required operations based on
the input word. Let me know if you have any que
stions or need further assistance2
1github.com2github.com
You
Write a programme in Java to input a sentence
from the user and count the number of times the
word an and and are present in the sentence.
Write the steps algorithm and variable
description for the programme. Also print the
terminal window
Copilot
Sure! Let's create a Java program to input a sente
nce from the user and count the number of times
the words "an" and "and" are present in the sent
ence. I'll also provide the algorithm, variable desc
riptions, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using a space
as the delimiter.
5.Initialize counters for "an" and "and".
6.Iterate through the list of words.
 Increment the respective counter if the
word is "an" or "and".
7.Output the counts of "an" and "and".
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 anCount: Counter for the occurrences of the
word "an".
 andCount: Counter for the occurrences of the
word "and".
Java Program:
java
Copy
import java.util.Scanner;

public class WordCount {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counters
int anCount = 0;
int andCount = 0;

// Iterate through the words


for (String word : words) {
if (word.equals("an")) {
anCount++;
} else if (word.equals("and")) {
andCount++;
}
}

// Output the results


System.out.println("Number of times 'an' is
present: " + anCount);
System.out.println("Number of times 'and' is
present: " + andCount);
scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a WordCount class with a main meth
od.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize counters anCount and andCount to
zero.
8.Iterate through the array of words:
 Increment anCount if the word is "an".
 Increment andCount if the word is "and"
.
9.Output the counts of "an" and "and".
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple and an orange are on
the table.
Number of times 'an' is present: 2
Number of times 'and' is present: 1
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java Using the scanner
class to modify a word by bringing all the vowels
in the world at the begin followed by consonants.
re concatenated with n (2) Write the steps
algorithm and the variable description of the
programme Also print the terminal window
Copilot
Let's create a Java program that rearranges a wor
d by bringing all the vowels to the beginning, foll
owed by the consonants, and then concatenates
"n" at the end. I'll also provide the algorithm, vari
able description, and an example of the terminal
output.
Algorithm:
1.Start
2.Accept a word input from the user.
3.Initialize two empty strings: one for vowels
and one for consonants.
4.Iterate through each character in the word.
 Check if the character is a vowel. If so, a
dd it to the vowels string.
 If the character is a consonant, add it to t
he consonants string.
5.Concatenate the vowels string with the cons
onants string and add "n" at the end.
6.Output the modified word.
7.End
Variable Description:
 word: The input word provided by the user.
 vowels: A string to store all the vowels found
in the word.
 consonants: A string to store all the consonan
ts found in the word.
 modifiedWord: The final modified word after r
earranging and concatenating "n".
Java Program:
java
Copy
import java.util.Scanner;

public class VowelConsonantModification {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a word: ");
String word = scanner.nextLine();

// Initialize empty strings for vowels and


consonants
String vowels = "";
String consonants = "";

// Iterate through each character in the word


for (char ch : word.toCharArray()) {
if (isVowel(ch)) {
vowels += ch;
} else {
consonants += ch;
}
}
// Concatenate vowels and consonants, then
add "n"
String modifiedWord = vowels + consonants
+ "n";

// Output the modified word


System.out.println("Modified word: " +
modifiedWord);

scanner.close();
}

public static boolean isVowel(char ch) {


ch = Character.toLowerCase(ch); // Make the
check case-insensitive
return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelConsonantModification class
with a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a word and read th
e input.
5.Initialize two empty strings, vowels and con
sonants, to store vowels and consonants sep
arately.
6.Iterate through each character in the word:
 Check if the character is a vowel using th
e isVowel method. If so, add it to the vow
els string.
 If the character is a consonant, add it to t
he consonants string.
7.Concatenate the vowels string with the cons
onants string and add "n" at the end to form
modifiedWord.
8.Output the modified word.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a word: HELLO
Modified word: EOHLn
Enter a word: JAVA
Modified word: AJAAn

Enter a word: COMPUTER


Modified word: OUECMPTRn
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java using scanner class to
check whether a sentence has a word beginning
with a capital letter or not Also write the steps
algorithm variable description and print the
terminal window
Copilot
Absolutely! Let's write a Java program that check
s if a sentence contains a word beginning with a
capital letter. I'll provide the algorithm, variable d
escription, and an example of the terminal output
.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Split the sentence into words using space as
a delimiter.
4.Initialize a flag to check for words starting w
ith a capital letter.
5.Iterate through the words:
 Check if the first character of each word i
s a capital letter.
 Set the flag if a capital letter is found.
6.Output the result based on the flag.
7.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 hasCapitalWord: A boolean flag to indicate if t
here is a word starting with a capital letter.
Java Program:
java
Copy
import java.util.Scanner;

public class CapitalLetterCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Accept user input
System.out.print("Enter a sentence: ");
String sentence = scanner.nextLine();

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize flag
boolean hasCapitalWord = false;

// Iterate through the words


for (String word : words) {
if
(Character.isUpperCase(word.charAt(0))) {
hasCapitalWord = true;
break;
}
}

// Output the result


if (hasCapitalWord) {
System.out.println("The sentence
contains a word beginning with a capital letter.");
} else {
System.out.println("The sentence does
not contain a word beginning with a capital
letter.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a CapitalLetterCheck class with a mai
n method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Split the sentence into words using the split
method with space as the delimiter.
6.Initialize a boolean flag hasCapitalWord to f
alse.
7.Iterate through the array of words:
 Check if the first character of each word i
s a capital letter using Character.isUpper
Case method.
 Set hasCapitalWord to true and break the
loop if a capital letter is found.
8.Output the result based on the value of hasC
apitalWord.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a sentence: This is a Test sentence.
The sentence contains a word beginning with a
capital letter.

Enter a sentence: this is a test sentence.


The sentence does not contain a word beginning
with a capital letter.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
write to programme in Java using scanner class
to accept a sentence and calculate the frequency
of word that begin with a Vowel Also write the
steps algorithm and variable description for the
programme and print the terminal window.
Copilot
Sure! Let's create a Java program that accepts a
sentence from the user, calculates the frequency
of words that begin with a vowel, and prints the r
esult. I'll provide the algorithm, variable descripti
on, and an example of the terminal output.
Algorithm:
1.Start
2.Accept a sentence input from the user.
3.Convert the sentence to lowercase to ensure
case insensitivity.
4.Split the sentence into words using space as
a delimiter.
5.Initialize a counter for words that begin with
a vowel.
6.Iterate through the list of words.
 Check if the first character of each word i
s a vowel.
 Increment the counter if a word begins
with a vowel.
7.Output the frequency of words that begin wi
th a vowel.
8.End
Variable Description:
 sentence: The input sentence provided by th
e user.
 words: An array of words obtained by splittin
g the sentence.
 vowelCount: Counter for the frequency of wor
ds that begin with a vowel.
Java Program:
java
Copy
import java.util.Scanner;

public class VowelWordFrequency {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a sentence: ");
String sentence =
scanner.nextLine().toLowerCase(); // Convert to
lowercase

// Split the sentence into words


String[] words = sentence.split(" ");

// Initialize counter
int vowelCount = 0;

// Iterate through the words


for (String word : words) {
if (word.length() > 0 &&
isVowel(word.charAt(0))) {
vowelCount++;
}
}

// Output the frequency of words that begin


with a vowel
System.out.println("Number of words
beginning with a vowel: " + vowelCount);

scanner.close();
}

public static boolean isVowel(char ch) {


return ch == 'a' || ch == 'e' || ch == 'i' || ch
== 'o' || ch == 'u';
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create a VowelWordFrequency class with a
main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a sentence and rea
d the input.
5.Convert the sentence to lowercase to ensure
the search is case-insensitive.
6.Split the sentence into words using the split
method with space as the delimiter.
7.Initialize a counter vowelCount to zero.
8.Iterate through the array of words:
 Check if the word length is greater than
0 and if the first character of each word is
a vowel using the isVowel method.
 Increment vowelCount if a word begins
with a vowel.
9.Output the frequency of words that begin wi
th a vowel.
10. Close the Scanner object to free up reso
urces.
Example Terminal Output:
shell
Copy
Enter a sentence: An apple a day keeps the
doctor away.
Number of words beginning with a vowel: 4

Enter a sentence: This is an example sentence.


Number of words beginning with a vowel: 2

Enter a sentence: Hello World!


Number of words beginning with a vowel: 0
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!
You
Write a programme in Java to check if a given
number is in Armstrong number or not. Also write
the variable description steps and algorithm for
the programme and print the terminal window.
Copilot
Sure! Let's create a Java program that checks if a
given number is an Armstrong number. I'll also pr
ovide the algorithm, variable descriptions, and an
example of the terminal output.
Algorithm:
1.Start
2.Accept a number input from the user.
3.Initialize variables to store the original num
ber, a copy of the number, and the result.
4.Calculate the number of digits in the numbe
r.
5.Iterate through each digit of the number:
 Extract the last digit.
 Raise the digit to the power of the numb
er of digits and add it to the result.
 Remove the last digit from the number.
6.Compare the result with the original number
to check if it's an Armstrong number.
7.Output the result.
8.End
Variable Description:
 number: The input number provided by the u
ser.
 originalNumber: A copy of the original numbe
r to compare with the result.
 n: The number of digits in the input number.
 result: The sum of each digit raised to the po
wer of n.
 temp: A temporary variable to store the curre
nt digit being processed.
Java Program:
java
Copy
import java.util.Scanner;

public class ArmstrongNumberCheck {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept user input


System.out.print("Enter a number: ");
int number = scanner.nextInt();

// Initialize variables
int originalNumber = number;
int result = 0;
int n = String.valueOf(number).length();

// Check if the number is an Armstrong


number
while (number != 0) {
int temp = number % 10;
result += Math.pow(temp, n);
number /= 10;
}

// Output the result


if (result == originalNumber) {
System.out.println(originalNumber + " is
an Armstrong number.");
} else {
System.out.println(originalNumber + " is
not an Armstrong number.");
}

scanner.close();
}
}
Steps Explained:
1.Import the Scanner class to accept user inpu
t.
2.Create an ArmstrongNumberCheck class wit
h a main method.
3.Instantiate the Scanner object to read input
.
4.Prompt the user to enter a number and read
the input.
5.Initialize variables originalNumber to store t
he original number, result to store the sum of
digits raised to the power of the number of di
gits, and n to store the number of digits in th
e input number.
6.Use a while loop to process each digit of the
number:
 Extract the last digit using the modulus
operator %.
 Raise the digit to the power of n using M
ath.pow and add it to result.
 Remove the last digit from the number u
sing integer division /.
7.Compare result with originalNumber. If they
are equal, the number is an Armstrong numb
er; otherwise, it is not.
8.Output the result.
9.Close the Scanner object to free up resource
s.
Example Terminal Output:
shell
Copy
Enter a number: 153
153 is an Armstrong number.

Enter a number: 123


123 is not an Armstrong number.
Feel free to run the above code on your local mac
hine or any online Java compiler to see how it wor
ks. Let me know if you have any questions or nee
d further assistance!

You might also like