Concept explainers
(Format an integer) Write a method with the following header to format the integer with the specified width.
public static String format(int number , int width)
The method returns a string for the number with one or more prefix 0s. The size of the string is the width. For example, format (34, 4) returns 0034 and format (34, 5) returns 00034. If the number is longer than the width, the method returns the string representation for the number. For example, format (34 , 1 ) returns 34. Write a test program that prompts the user to enter a number and its width, and displays a string returned by invoking format (number, width).
Trending nowThis is a popular solution!
Chapter 6 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Electric Circuits. (11th Edition)
Mechanics of Materials (10th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Concepts Of Programming Languages
Starting Out With Visual Basic (8th Edition)
- public String firstAndLast(String str) { //declare and create your first char //declare and create your second char //return your first and last char as a String }arrow_forwardRepeating String Write a method that takes a String and an int and return a String that is the original String repeated n times. For example, repeatString("Famous", 3) should return "FamousFamousFamous" The method signature should be public String repeatString(String str, int n) public String repeatString(String str, int n) { //declare a string variable //set up statements for repeating n number of times //create the appropriate return statement }arrow_forwardIn Java code do the following:Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String:arrow_forward
- Class Utilities { Method Details addDelimiter: public static java.lang.String addDelimiter(java.lang.String str, char delimeter) Returns a string where characters are separated by the specified delimeter character. A string with a single character will not have a delimeter added. The space character is consider a character (similar to character 'A'). You can assume str will never be the empty string. You may not use an auxiliary method in order to implement this method. Your implementation must be recursive and you may not use any loop construct. Note: In java given two characters a and b, a + b will not create a string. To create a string, append a to the empty string and the result to b. From the String class, the only methods you can use are length(), isEmpty(), charAt() and substring. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: str - delimeter - Returns: String with characters…arrow_forward(Intro to Java) explain the answers to the below questions using step-by-step explanation.arrow_forwardNOTE: JAVA language Write a program that asks the user for his first name and then prints it using a function/method called printName(). We do not expect the first name to exceed 20 letters. Then the program should print the name with a space between each character. Example: if the first name is Maryam, the :program will print Maryam -1 Maryam -2arrow_forward
- :Write some statements that display a list of integers from 10 to 20 inclusive ,each with its square root next to it. Write a single statement to find and display the sum of the successive even integers 2, 4, ..., 200. (Answer: 10 100) Ten students in a class write a test. The marks are out of 10. All the marks are entered in a MATLAB vector marks. Write a statement to find and display the average mark. Try it on the following marks: 580 10 3 85794 (Answer: 5.9)arrow_forward1. Write the method named shift3() You are given a String str. Return a new String where all of the characters are "shifted" by 3. Here is the algorithm to do this 1. Visit each character in the String 2. Create a new char by adding 3 3. Store the new character in the output string Examples: shift3("hello") returns "khoor" shift3("cat") returns "fdw" shift3("frog") returns "iurj" @param str the String to start with @return the rotated String as described herearrow_forwardGive solution First Name: Saira Last Name: Tabasum Give Java program of given questionarrow_forward
- Name:- Mit (Question-1) Note:- Please type this java code and also need an output for this given Java program.arrow_forwardClass: DoubleMethod Write a method using the header below public static double readDouble(String prompt) that displays the prompt string, followed by a space, then reads a floating-point number from the user, and returns it. Here is a typical usage: salary = readDouble("Please enter your salary:");percentageRaise = readDouble("What percentage raise would you like?");Write a test program to test the method.arrow_forwardPractice / Frequency of Characters Write a method that returns the frequency of each characters of a given String parameter. If the given String is null, then return null If the given String is empty return an empty map Example input: output: empty map explanation: input is empty Example input: null output: null explanation: input is null. Since problem output is focused on the frequency we can comfortably use Map data structure. Because we can use characters as key and the occurrences of them as value. Example input: responsible output: {r=1, e=2, s=2, p=1, o=1, n=1, i=1, b=1, l=1} explanation: characters are keys and oc values ences arearrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT