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

Can someone help me to include a void method into this code? Thank You! import j

ID: 3686050 • Letter: C

Question

Can someone help me to include a void method into this code?

Thank You!

import java.util.*;

public class Lab4_Problem4
{
public static void main(String[] args)
{
String sInput;
int iLength;
Scanner cin = new Scanner(System.in);
  
System.out.print("Type a string from 5 to 25 characters and press Enter: ");
sInput = cin.next();
iLength = sInput.length();
  
if (iLength < 5 || iLength > 25)
{
System.out.println("Error: length must be from 5 to 25 characters");
}
else
{
System.out.println("String length: " + iLength);
System.out.println("Uppercase: " + sInput.toUpperCase());
System.out.println("Lowercase: " + sInput.toLowerCase());
System.out.println("Characters in the first positions: " + sInput.substring(0, 1));
System.out.println("Position of the @: " + sInput.indexOf("@"));
System.out.println("Last four characters: " + sInput.substring(iLength - 4, iLength));
}
}
}

Explanation / Answer

import java.util.*;
public class Lab4_Problem4
{
public static void main(String[] args)
{
String sInput;
int iLength;
Scanner cin = new Scanner(System.in);
  
System.out.print("Type a string from 5 to 25 characters and press Enter: ");
sInput = cin.next();
iLength = sInput.length();
void_function(sInput, iLength);

}
public static void void_function(String sInput, int iLength)
{
if (iLength < 5 || iLength > 25)
{
System.out.println("Error: length must be from 5 to 25 characters");
}
else
{
System.out.println("String length: " + iLength);
System.out.println("Uppercase: " + sInput.toUpperCase());
System.out.println("Lowercase: " + sInput.toLowerCase());
System.out.println("Characters in the first positions: " + sInput.substring(0, 1));
System.out.println("Position of the @: " + sInput.indexOf("@"));
System.out.println("Last four characters: " + sInput.substring(iLength - 4, iLength));
}
}
}

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