Question
in java please
Create an array of characters. Ask the user to enter two characters. Tell the user which character occurs more frequently For
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

import java.util.Scanner;
public class Main{

public static void main(String []args){
Scanner sc=new Scanner(System.in);
char arr[]={'a','b','c','d','a','?','e','a','c','f','g'};
System.out.println("Enter 2 characters separate by spaces: ");
char a,b;
a=sc.next().charAt(0);
b=sc.next().charAt(0);
int ct1=0,ct2=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]==a)
{
ct1++;
}
if(arr[i]==b)
{
ct2++;
}
  
}
if(ct1>ct2)
{
System.out.println("The most frequent charcter of the 2 is "+a);
}
else
{
System.out.println("The most frequent charcter of the 2 is "+b);
  
}
}
}

M Someone commented x C Hi I Need Help With Th x C In Java Please | Chegg. X Online Java Compiler - X C My Q&A | Chegg.com ~

Note: Brother According to HomeworkLib's policy we are only allowed to answer first part if there are many. So, I request you to post other part as separate posts.

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
in java please Create an array of characters. Ask the user to enter two characters. Tell...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a java program that with an integer array that has ten numbers in it. Ask...

    Create a java program that with an integer array that has ten numbers in it. Ask the user for an integer. Search your array and if found it tell them at what position it was found. If not found tell them the number was not found.

  • (Java) HELP! Create a program that will ask the user to enter their first name and...

    (Java) HELP! Create a program that will ask the user to enter their first name and their favorite number. Ask the user if they would like the information repeated back to them. If they type "Y" display the answers back to them. If they type anything else, display the word "Goodbye". An example of what your output window should look like is below. The system-generated output is in red. The user-provided input is in green. (Your actual program will only...

  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • java create an array of n intergers. ask the user for entry of an integer n....

    java create an array of n intergers. ask the user for entry of an integer n. populate this array with first n palindromes.

  • In Java Create a 2D 10x10 array of Characters named UPPERCASE containing an uppercase character in...

    In Java Create a 2D 10x10 array of Characters named UPPERCASE containing an uppercase character in each cell. Next, traverse the array and determine if any rows contain both ‘X’ and ‘R’. If a row does contain both, return true, else return false once you have traversed the entire array

  • Using java program, create a Username class. ask user to type username 1)username length have to...

    Using java program, create a Username class. ask user to type username 1)username length have to >1 and <15 2)username can not include any special character (ex.!@##$}{|\....) ,but it also have to type Spanish or other foreign language 3)user can not include any empty space (ex. user name) all of three error have to print out. and if there is any error contains, have to ask user to input user name again. for example: input username: #$%he f username can't...

  • In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the...

    In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the user to input a size of an array. Create an array of type int. Ask a user to fill the array. Create a functions sortArray() and mostFrequency(). The sortArray() function will sort number into incrementing order. The sorting function must be implemented from scratch and it must not use any function from the library. Feel free to use any sorting algorithm. The program will...

  • ASSIGNMENT: Create a program to do the following: BONUS: A bonus of 20 points if you create the p...

    ASSIGNMENT: Create a program to do the following: BONUS: A bonus of 20 points if you create the program in such a way that there is no limit on the number of names to be handled. 1) Read in names to sort until the user types the “enter” key as the first character of a “C-type” string (the maximum number of names is 20, there is not a maximum length to a name), using a two dimensional array of characters....

  • Create a Java program which asks the user how many names they want to enter. The...

    Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.

  • IN JAVA... Write a program that would create a one-dimensional array of length 7, with user-specified...

    IN JAVA... Write a program that would create a one-dimensional array of length 7, with user-specified values and display the array values. Then search the array for the smallest value and display both the value and its position in the array.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT