Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esercizio L.3.3 #32

Open
rimaout opened this issue Mar 21, 2024 · 2 comments
Open

Esercizio L.3.3 #32

rimaout opened this issue Mar 21, 2024 · 2 comments

Comments

@rimaout
Copy link
Member

rimaout commented Mar 21, 2024

image
@alem1105
Copy link
Member

    public static void es3(String s1, String s2, String s3) {
        String[] array = { s1, s2, s3 };
        int maxlen = s1.length();
        for (int i = 1; i < array.length; i++) {
            if (array[i].length() > maxlen) {
                maxlen = array[i].length();
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < maxlen; i++) {
            if (i < s1.length()) {
                output.append(s1.charAt(i));
            } else {
                output.append(" ");
            }
            if (i < s2.length()) {
                output.append(s2.charAt(i));
            } else {
                output.append(" ");
            }
            if (i < s3.length()) {
                output.append(s3.charAt(i));
            } else {
                output.append(" ");
            }
            output.append("\n");
        }
        System.out.println(output);
    }

@alem1105 alem1105 added Risolto and removed To-Do labels Mar 24, 2024
@LiciaMor18
Copy link

import java.util.Arrays;

public class N2 {
	
	public static void stampaVerticale(String s1, String s2, String s3) {
		
		int max= Math.max( Math.max(s1.length(), s2.length()),s3.length());
		
		char[] new_s1= Arrays.copyOf( s1.toCharArray(),max);
		char[] new_s2=Arrays.copyOf(s2.toCharArray(),max);
		char[] new_s3=Arrays.copyOf(s3.toCharArray(),max);
		
		for (int i=0;i<max;i++) {
			System.out.println(new_s1[i]+" " +new_s2[i]+" "+new_s3[i]);
			}				
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants