Recall your very first challenge? If not, look for a little green tag. You came up with some algorithm to lay black and white tiles on a floor. Now that you know how to code, can you turn your pseudo code into Java code?
Feel free to use a letter or a number to represent a "black" tile or a "white" tile. For instance,
BBBBBBBBBBBBB
B B
B B
B BBB B
B B
B B
BBBBBBBBBBBBB
import java.util.*;
class Randomizer {
public static void main(String[] args) {
System.out.println("Please enter the amount of rows");
Scanner r=new Scanner(System.in);
int r1=r.nextInt();
System.out.println("Please enter the amount of columns");
//Scanner c=new Scanner(System.in);
int c1=r.nextInt();
for(int r0=1; r0<=r1; r0++ )
{
if(r0==1 || r0==r1)
{
for(int c0=1; c0<=c1; c0++ )
{
System.out.print("b");
}
System.out.println();
}
else if(r0==(r1/2)+1)
{
for(int c0=1; c0<=(c1-1); c0++ )
{
if(c0==1 || c0==(c1-1))
{
System.out.print("b");
}
if(c0==c1/2)
{
System.out.print("b");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
else
{
for(int c0=1; c0<=c1; c0++ )
{
if(c0==1 || c0==c1){
System.out.print("b");
}
if(1<c0 && c0<c1){
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
import java.util.Scanner;
class fringe {
public static void main(String[] args) {
Scanner John = new Scanner(System.in);
System.out.println("Please input the length of the border (must be greater than or equal to 5)");
double columns = John.nextInt();
System.out.println("Please input the width of the border (must be greater than or equal to 5)");
double rows = John.nextInt();
double x = Math.ceil(rows/2) - 2;
if(columns < 5 || rows < 5){
System.out.println("They must be greater than or equal to 5");
System.exit(0);
}
for(int i=1; i<=columns; i++){
System.out.print("B");
}
System.out.println();
for(int i=1; i<=x; i++){
System.out.print("B");
for(int j=1; j<=columns-2; j++){
System.out.print(" ");
}
System.out.print("B");
System.out.println();
}
for(int i=1; i <= (rows%2)*(-1) + 2; i++){ //does it twice if rows is even
System.out.print("B");
for(int j=1; j<=x; j++){
System.out.print(" ");
}
for(int j=1; j<=columns - (2+ 2*x); j++){
System.out.print("B");
}
for(int j=1; j<=x; j++){
System.out.print(" ");
}
System.out.print("B");
System.out.println();
}
for(int i=1; i<=x; i++){
System.out.print("B");
for(int j=1; j<=columns-2; j++){
System.out.print(" ");
}
System.out.print("B");
System.out.println();
}
for(int i=1; i<=columns; i++){
System.out.print("B");
}
}
}