Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Cuadrado de ceros y unos: En el programa principal pida dos enteros,
- * H y L. Dibuje un rectángulo de n filas y m columnas formado por "0"
- * y "1" alternados, tal que las filas pares comiencen con un 0 y las
- * impares con un 1.*/
- import java.util.*;
- public class tarea08{
- public static void main (String args[]) {
- Scanner tec = new Scanner(System.in);
- System.out.print("Ingrese el numero de filas: ");
- int H = tec.nextInt();
- H = validar(H,"filas");
- System.out.print("Ingrese el numero de columnas: ");
- int L = tec.nextInt();
- L = validar(L,"columnas");
- cuadrado(H,L);
- }
- public static int validar(int V,String nombre){
- Scanner tex = new Scanner(System.in);
- while (V<=0){
- System.out.println("Error, numero no valido!");
- System.out.print("Ingrese el numero de "+nombre+": ");
- V = tex.nextInt();
- }return V;
- }
- public static void cuadrado(int H, int L){
- for(int h=0;h<H;h++){
- for(int l=0;l<L;l++){
- if((l+h)%2==0){
- System.out.print("1 ");
- }else{
- System.out.print("0 ");
- }}
- System.out.println();}
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement