Question

In: Computer Science

Java- creat a method that takes two char parameters. Return a String containing all characters, in...

Java- creat a method that takes two char parameters. Return a String containing all characters, in order, from the first char parameter (inclusive) to the last (inclusive). For instance, input('a', 'e'), and return "abcde".

Solutions

Expert Solution

Program:

import java.io.*;       // import packages
import java.util.*;       // import packages
public class Sequence       // Class Sequence
{
   public static String input(char ch1,char ch2)   // Method input takes two char parameters ch1,ch2
   {
       String s1="";   // initialize string s1
       for(char ch=ch1;ch<=ch2;ch++)   // repeat from first character to last character
       s1=s1+ch;       // append characters between ch1 to ch2
       return s1;       // return s1
   }   // end input method
   public static void main(String[] args)    // main function
   {
       Scanner sc=new Scanner(System.in);   // object create for Scannet class
       char c1,c2;       // two char variables
       System.out.println("\nEnter First Character[a-z]/[A-Z]");   // display message
       c1=sc.next().charAt(0);   // read character from user
       System.out.println("\nEnter Second Character[a-z]/[A-Z]"); // display message
       c2=sc.next().charAt(0);   // read character from user
       System.out.println(input(c1,c2));   // call method and display result
   }   // end main funcion
}   // end class

Output:

Program Screenshot:

Note:

The Above Program Done by using jdk1.7.

File Name is Sequence.java


Related Solutions

Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and...
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and returns a boolean. The method should return true if both arrays contain the same values (case sensitive), otherwise returns false. Note - the two arrays must be the same length and the values must be in the same order to return true. Part  2 Write a method named generateArray that accepts an int size as its parameter and returns an int[] array where each element...
Takes a string and removes all spaces and special characters, and converts // to upper case,...
Takes a string and removes all spaces and special characters, and converts // to upper case, returning the result // Pre: inString contains a string // Post: Returns a string with all spaces and special characters removed and // converted to upper case in c++ please
Java Write a valid Java method called printReverse that takes a String as a parameter and...
Java Write a valid Java method called printReverse that takes a String as a parameter and prints out the reverse of the String. Your method should not return anything. Make sure you use the appropriate return type.
write a java program to Translate or Encrypt the given string : (input char is all...
write a java program to Translate or Encrypt the given string : (input char is all in capital letters) { 15 } *) Each character replaced by new character based on its position value in english alphabet. As A is position is 1, and Z is position 26. *) New characters will be formed after skipping the N (position value MOD 10) char forward. A->A+1= B , B->B+2=D ,C->C+3=F, .... Y->Y+(25%10)->Y+5=D A B C D E F G H I...
How to write Method in Java: public static in firstLetterFreq(char letter, String[] words] { // it...
How to write Method in Java: public static in firstLetterFreq(char letter, String[] words] { // it returns 0 if (words == null OR words.length == 0) // returns number of times letter is the first letter of a String in words array // use equalIgnoreCase to check if letter and str.charAt(0) are equal and ignoring case }
JAVA coding language: Consider the method getAllCharAsString: public statis String getAllCharAsString(String inputStr, char target) { }...
JAVA coding language: Consider the method getAllCharAsString: public statis String getAllCharAsString(String inputStr, char target) { } The method accepts a String parameter, inputStr, and a char parameter, target. It returns the result string consisting of all the characters in inputStr which match the target character (matching is case sensitive, for example, 'c' does not match "C"). If the characters match, the character is appended to the result String. After all the characters in inputStr have been compared, the method returns...
Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT