WRITTEN IN JAVA
Complete the method printIndices that accepts a String source and a character search, and prints the position of each occurrence of the search value in source. For example:
Input: source = "String Programming in Java is fun", search = 'i'
Console Output: 3 15 19 27
Template provided from question:
public static int printIndices(String source, char
search)
{
}
public static void main(String[] args)
{
System.out.println("Expected
printIndices() prints indices 3 15 19 27 for search letter i :
");
printIndices(sentence, 'i');
}
public class PrintIndices {
public static void printIndices(String source, char search)
{
for (int i = 0; i < source.length(); i++) {
if (source.charAt(i) == search) {
System.out.print(i + " ");
}
}
System.out.println();
}
public static void main(String[] args)
{
System.out.println("Expected printIndices() prints indices 3 15 19 27 for search letter i : ");
printIndices("String Programming in Java is fun", 'i');
}
}
WRITTEN IN JAVA Complete the method printIndices that accepts a String source and a character search,...
Complete the printPalindrome method in the provided Palindrome.java program. The printPalindrome method accepts a String as a parameter and prints whether the parameter String is a palindrome (i.e., reads the same forwards as it does backwards, for example, "abba" or "racecar"). Make the code case-insensitive, so that words like "Abba" and "Madam" will be considered palindromes. import java.util.*; /** * Determines if a user entered String is a palindrome, which means the String * is the same forward and reverse....
JAVA Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String. Then, modify the method you just wrote so it displays the String backwards. The following code does not correctly display the String backwards. It merely moves the first character of the String to the end: public static void displayCharacter(String s) { if(s.length() == 0) return; else ...
In Java This is the method we did in class. How do I reverse the string "monday"? If I could get the string "onday" reversed (to produce "yadno" then all I have to do is append the first character to make "yadnom". import java.util.Scanner; public class Lab12Num2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); System.out.println("The string entered was " + s); System.out.println("The string printed backwards is "+ printBackwards(s)); } public static String printBackwards(String one)...
Debug following methods(longestRun(finds how many times a character got repeated), findLastP(finds last p in a string), findFirstP(finds first p in a string)) in java language. public class simpleLoops { /** * @param args */ public static void main(String[] args) { System.out.println(longestRun("aabbbccd")); System.out.println("Expected 3"); System.out.println(longestRun("aaa")); System.out.println("Expected 3"); System.out.println(longestRun("aabbbb")); System.out.println("Expected 4"); int count = countP("Mississippi"); System.out.println(count); int result = findLastP("Mississippi"); System.out.println(result); result = findFirstP("stop"); System.out.println(result); result = findFirstP("xxxyyyzzz"); System.out.println(result); } /** *...
Write a JAVA program that has a method which accepts a string and prints it back to the user with all vowels replaced with *'s (multiple asterisks not '*s') with a new line after the string. The method signature should look like this: public static void replacePrint(String input)
Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...
Need the answer in Java
1.17 LAB*: Program: ASCII art
This zyLab activity is the traditional programming
assignment, typically requiring a few hours over a week. The
previous sections provide warm up exercises intended to help a
student prepare for this programming assignment.
(1) Output this tree. (2 pts)
*
***
*****
*******
***
(2) Below the tree (with two blank lines), output this cat. (3
pts)
/\ /\
o o
= =
---
Hint: A backslash \ in a...
Java Method Resolution : Consider the following example: What is printed on the console if Main is executed, and why? How the codes could be improved? public class Main { public static void main(String[] args) throws Exception { A obj = null; obj.foo(); } } public class A { public void foo() { System.out.println(“foo in A”); } }
Java 7 Write a constructor for the MightyByte class so it can accept a String argument and set the bits field. Complete the for loop in the getDecimalValue method. class Main { public static void main(String[] args) { MightyByte myByte = new MightyByte("00000101"); System.out.println(myByte.getDecimalValue()); } } class MightyByte { private String bits; // write the constructor here public int getDecimalValue() { int decimalValue = 0; int intValue; int power = 7; for (int i = 0; i...
Write a static method called encodeString that takes a string as input and prints to the console a word where each letter is advanced by one value. In addition, your method should return the encoded String. You may make use of the method provided below to help you. public static char encode(char x) { int current = x; current++; return (char)current; } This method takes a character and returns an "encoded" character. In other words, encode('a') will return 'b'. Your...