Problem:
We must calculate how many tiles we need to cover a wall without using multiplication or division.
For example:
WallLength: 540 (user input)
WallHeight:240 (user input)
TileLength: 60 (user input)
TileHeight:40 (user input)
Row: 9 (prog - output)
Column: 6 (prog Output)
Solution:
We will solve this using only while loops and subtraction in java. We must subtract until we can't fit anymore tiles, like so:
Scanner scanner = new Scanner(System.in);
System.out.println("INPUT WALL DATA");
System.out.print("length: ");
double wallLength = scanner.nextDouble();
System.out.print("height: ");
double wallHeight = scanner.nextDouble();
System.out.println("INPUT TILE DATA");
System.out.print("length: ");
double tileLength = scanner.nextDouble();
System.out.print("height: ");
double tileHeight = scanner.nextDouble();
// since you cant divide just subtract until you cant anymore (what divide does)
int row = 1;
while(tileLength < wallLength){
wallLength -= tileLength;
row++;
}
int column = 1;
while(tileHeight < wallHeight){
wallHeight -= tileHeight;
column++;
}
System.out.println("Row(s): "+row+"\nColumn(s): "+column);
We are dividing without using the divide operation, so the answer meets the requirements.