← Foro de Java (básico)

necesito ayuda urgentemente

Hilo en el foro de Java (básico) · 31 de Diciembre del 2008 · 4 respuestas
thevirtualX31 de Diciembre del 2008
Pregunta
BUENO PUES ESTOY APRENDIENDO A PROGRAMAR Y ME ENCARGARON UN APRACTICA EN LA QUE TENGO
QUE REALIZAR VARIOS PROGRAMAS Y LA VERDAD NO ENCUANTRO COMO

lo que tengo q hcer es un progrma que
dibuje un cuadrado con asteriscos(**********),

un trinaguloequilatero,

un triangulo isoceles,

un rectangulo,

un cuadrado sin relleno


POR FAVOAR QUIEN PUEDA AYUDARME SE LO AGRADECERE MUCHO

Respuestas 4

Makaveli31 de Diciembre del 2008
Para el cuadrado de asteriscos puede ser este:
//------------------------------------------------

import java.io.*;
public class CuadradoAsteriscos {
public static void main(String arg[])throws IOException{
int lado;
BufferedReader tecla = new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"Ingresar cantidad de asteriscos por lado : \");
lado = Integer.parseInt(tecla.readLine());
char[][] c=new char[lado][lado];

for(int i=0;i<lado;i++){
for(int j=0;j<lado;j++){
c[i][j]=\\'*\\';
}
}
for(int i=0;i<lado;i++){
for(int j=0;j<lado;j++){
System.out.print(c[i][j]+\" \");
}System.out.println();
}
}
}


//------------------------------------------------
Makaveli31 de Diciembre del 2008
Para el Triangulo Isoseles
//---------------------------
import java.io.*;
class IsoselesAsteriscos{
public static void main(String arg[])throws IOException{
int l,r,i,j;
char matr[][]=new char[100][100];
int f,c;

BufferedReader tecla = new BufferedReader(new InputStreamReader(System.in));
System.out.println("INGRESAR NUMERO DE FILAS : ");f=Integer.parseInt(tecla.readLine());
c=2*f-1;
l=((c+1)/2)-1;
r=l;
for(i=0;i<f;i++){
l--;r++;
for(j=0;j<c;j++){

if(j>l && j<r)matr[i][j]='*';
else matr[i][j]=' ';
}

}

for(i=0;i<f;i++){System.out.print("t");
for( j=0;j<c;j++){
System.out.print(matr[i][j]+" ");

} System.out.println();
}
}
}

//---------------------------
Makaveli31 de Diciembre del 2008
EL CUADRADO CON ASTERISCOS SALIO MAL, AKI ESTA:
//-----------------------------
import java.io.*;
public class CuadradoAsteriscos {
public static void main(String arg[])throws IOException{
int lado;
BufferedReader tecla = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingresar cantidad de asteriscos por lado : ");
lado = Integer.parseInt(tecla.readLine());
char[][] c=new char[lado][lado];

for(int i=0;i<lado;i++){
for(int j=0;j<lado;j++){
c[i][j]='*';
}
}
for(int i=0;i<lado;i++){
for(int j=0;j<lado;j++){
System.out.print(c[i][j]+" ");
}System.out.println();
}
}
}

//----------------------------
Makaveli31 de Diciembre del 2008
Rectangulo:

//--------------------------------
import java.io.*;
public class RectanguloAsteriscos {
public static void main(String arg[])throws IOException{
int lado;
BufferedReader tecla = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingresar cantidad de asteriscos por lado : ");
lado = Integer.parseInt(tecla.readLine());
char[][] c=new char[lado][lado*3];

for(int i=0;i<lado;i++){
for(int j=0;j<lado*3;j++){
c[i][j]='*';
}
}
for(int i=0;i<lado;i++){
for(int j=0;j<lado*3;j++){
System.out.print(c[i][j]+" ");
}System.out.println();
}
}
}
//--------------------------------
¿Buscas más hilos como este? Mira el foro de Java (básico) o usa el buscador.