Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java code. Looking for a simple solution to learn from. I\'m looking for method

ID: 3710452 • Letter: J

Question

Java code. Looking for a simple solution to learn from.

I'm looking for method that uses Stack to convert the passed string (case insensitive) to uppercase form. For example:

"Wooorrrrrllld" without quotes, it should return "WO3R5L3D".

"Maaaaaanny" without qutes, it should return "MA6N2Y"

If it's only one character, do not return the number 1 next to it.

For a starting method please use "public static String myFunction(String myString)".

myString is a String that is passed in.

The return should return the string with the number of occurences as the examples above.

However, if the string passed in is null or empty, it should return null.

Explanation / Answer

Solution:

code:

import com.mtsystems.coot.NativeHelper;

public class ImplicitDeclarations {

static {

// The online demo uses the example library "libc.so.6".

// Have a look at the translated programs for real values.

NativeHelper h = NativeHelper.get("libc.so.6");

h.bindDirect(ImplicitDeclarations.class);

}

public static native int toupper();

}

// ----- ----- Class 2: DemoTranslation ----- -----

package demo;

import static implicit_code.ImplicitDeclarations.toupper;

import com.mtsystems.coot.String8;

import java.util.Scanner;

public class DemoTranslation {

public static void myFunction(String8 str) {

int count;

for(int i = 0; str.get(i) != ''; ++i) {

count = 1;

while(str.get(i) == str.get(i + 1)) {

count++;

i++;

}

if(count > 1) {

System.out.print("" + ((char)Byte.toUnsignedInt((byte)toupper(str.get(i)))) + count);

} else {

System.out.print((char)Byte.toUnsignedInt((byte)toupper(str.get(i))));

}

}

}

public static void main(String[] args) {

String8 str = new String8(1_000);

byte ch;

int i, frequency = 0, count;

System.out.print("Enter a string: ");

str.copyFrom(STDIN_SCANNER.nextLine());

myFunction(str);

}

public final static Scanner STDIN_SCANNER = new Scanner(System.in);

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote