my code stock.com

Colored terminal output, loops example etc

Snippet options

Download: Download snippet as something-easy.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/*
GPL v3 code licensed
 */
package aulas;

/**
 *
 * @author geraldo gomes
 */
public class PrimeiraLista {
    private Integer qtd=3;

    public PrimeiraLista() {
        
    }
    
    public void Exercicio1LetraA(int A, int B, int C){
        /*
         * Testa o tipo de triangulo 
         */
        if((A==B) && (A==C) && (B==C)){
            System.out.println("o Triangulo é Equilatero");
        }else{
            if((A!=B) &&( A!=C) && (B!=C)){
                System.out.println("o Triangulo é Escaleno");
            }else{
                System.out.println("o Triangulo é Isóceles");
            }
        }
    }
    
    public void Exercicio1LetraB(int cor){
        /*
         * Cores para os numeros, se tiver em um terminal
         * que suporte os padrões ANSI as cores apareceram
         */
        char esc = 27;
        switch(cor){
            case 0:
            case 1:
            case 2:
                System.out.println(esc+"[1;31m"+cor+" vermelho");
                break;
            case 3:
            case 4:
                System.out.println(esc+"[0;31m"+cor+" laranja");
                break;
            case 5:
                System.out.println(esc+"[33m"+cor+" amarelo");
                break;
            case 6:
            case 7:
                System.out.println(esc+"[32m"+cor+" verde");
                break;
            case 8:
            case 9:
                System.out.println(esc+"[34m"+cor+" azul");
                break;
            default:
                System.out.println(esc+"[30m"+cor+"preto");
                break;
        }
        
    }
    public void Exercicio1LetraC(){
        int i,j,k;
        for(i=0;i<=qtd;++i){
            for (j=(qtd-i);j>0;--j)
                System.out.printf(" ");
            for (k=0;k<=(2*i);++k)
                System.out.printf("*");
            System.out.printf("\n");
        }
    }
    
    public void Exercicio1LetraD(){
        int i=0,j,k;
        while(i<=qtd){
            j=qtd-i;
            while((j--)>0)
                System.out.printf(" ");
            k=0;
            while((++k)<=(2*i)+1)
                System.out.printf("*");
            System.out.printf("\n");
            ++i;
        }
    }
    public void Exercicio1LetraE(){
        int i,j,k;
        for(i=qtd;i>=0;--i){
            for (j=(qtd-i);j>0;--j)
                System.out.printf(" ");
            for (k=0;k<=(2*i);++k)
                System.out.printf("*");
            System.out.printf("\n");
        }

    }
    public void Exercicio1LetraF(){
        int i=qtd,j,k;
        while(i>=0){
            j=qtd-i;
            while((j--)>0)
                System.out.printf(" ");
            k=0;
            while((++k)<=(2*i)+1)
                System.out.printf("*");
            System.out.printf("\n");
            --i;
        }
    }
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.