Solution :
CODE :
package countchar;
import java.util.Scanner;
public class CountChar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int countA=0, countB=0;
// ask user to enter string here
System.out.println("Enter String to count 'A' and 'B' : ");
String inputString = sc.nextLine();
// count number of A and B.
for(int i=0; i<inputString.length(); i++){
if(inputString.charAt(i) == 65){
countA++;
}
else if(inputString.charAt(i) == 66){
countB++;
}
}
// print the output :
System.out.println("Number of 'A' in String : " + countA);
System.out.println("Number of 'B' in String : " + countB);
}
}
Sample
output :
if you have any doubts
then you can ask in comment section if you find the solution
helpful then upvote the answer. Thank you.
Using Java language, Write a program that read a string from the keyboard and counts the...
C
language
2. Write a program to read in a string from the keyboard and only display the vowels and their positions index) in a table format. Enter a string: This is a test Here are the vowels and their positions:
write a C program to read in a string from the keyboard and display the whole string backward
This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...
Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...
3. Write a program in assembly language that reads a number from the keyboard and displays it on the screen. 4. Write a program in assembly language to ask two digits from the user, store the digits in the EAX and EBX register, respectively, add the values, store the result in a memory location 'res' and finally display the result.
Write a program to draw this number triangl using MIPS assembly
language
The number of rows is inputted from keyboard.
6. Write a program to draw this number triangle 1 1〈--|--〉1 The number of rows is inputted from keyboard.
6. Write a program to draw this number triangle 1 1〈--|--〉1 The number of rows is inputted from keyboard.
JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...
Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied. Will give thumbs up...
Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.
Given an unweighted directed graph G, write a program that counts and prints all simple paths from a given ‘s’ to a given ‘d’. Assume the graph G is represented using adjacent matrix. Using Java Language