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

Can someone please help me keep the contents of this program but code it differe

ID: 3545508 • Letter: C

Question


Can someone please help me keep the contents of this program but code it differently? I prefer to have the main in the bottom and function up top...


import java.util.Scanner;




public class p1 {




public static void main(String[] args) {




Scanner input=new Scanner (System.in);


String n;


System.out.println("Please enter a string:");


n=input.nextLine();




multi3(n);




}




public static void multi3 (String x)


{


if(x.length()%3==0)


{System.out.println("String is a multiple of three ");


for(int i=2;i<x.length();i+=3)


System.out.print(x.charAt(i));


}


else


System.out.print(x);


}




}


Explanation / Answer

import java.util.Scanner;

public class vote {

public static void multi3 ()

{

Scanner input=new Scanner (System.in);

String x;

x=input.nextLine();

if(x.length()%3==0)

{System.out.println("String is a multiple of three ");

for(int i=2;i<x.length();i+=3)

System.out.print(x.charAt(i));

}

else

System.out.print(x);

}


public static void main(String[] args) {

System.out.println("Please enter a string:");

multi3();

}

}