Question

In: Computer Science

Java Program // DO NOT USE BREAK OR CONTINUE :) You are allowed to use the...

Java Program

// DO NOT USE BREAK OR CONTINUE :)

You are allowed to use the following methods from the Java API:

  • class String
    • length
    • charAt
  • class StringBuilder
    • length
    • charAt
    • append
    • toString
  • class Character
    • any method
  • CANNOT use break or continue
  1. moveXDownLeft takes a char and a two dimensional array of char as input and returns nothing:
    The method should find the first occurrence of the char in the array (searching from "top" to "bottom" and "left" to "right"), and it should slide that character in the array down and to the left as far as it can go. Any characters on that diagonal are slide up and to the right to fill. Do not use Strings to solve this problem.

    > char[][] board = {{'a','b','c','X'},{'d'},{'e','f','g','h'},{'i','j','k'},{'l','m','n','o'}};
    > HW2.moveXDownLeft('X', board)
    > board
    { { a, b, c, f }, { d }, { e, i, g, h }, { X, j, k }, { l, m, n, o } }

Solutions

Expert Solution

CODE IN JAVA:

Board.java file:


public class Board {

   public static void moveXDownLeft(char ch , char[][] board) {
       int row=-1,col=-1;
       for(int i=0;i<board.length;i++) {
           for(int j=0;j<board[i].length;j++) {
               if(board[i][j]==ch) {
                   if(row==-1) {
                       row = i ;
                       col = j ;
                   }
               }
           }
       }
       if(row!=-1) {
           System.out.println("character is found at row = "+(row+1)+", column = "+(col+1));
       }
       else {
           System.out.println("Your character is not found....");
       }
   }
   public static void main(String[] args) {
       char[][] board = {{'a','b','c','X'},{'d'},{'e','f','g','h'},{'i','j','k'},{'l','m','n','o'}};
       moveXDownLeft('X', board);
      

   }

}

OUTPUT:


Related Solutions

Java program - you are not allowed to use arithmetic operations such as division (/), multiplication,...
Java program - you are not allowed to use arithmetic operations such as division (/), multiplication, or modulo (%) to extract the bits. In this exercise use only logic bit-wise operations. Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you CANNOT use the arithmetic division by...
Need in JAVA. You are to use Binary Trees to do this Program. Write a complete...
Need in JAVA. You are to use Binary Trees to do this Program. Write a complete program, which will process several sets of numbers: For each set of numbers you should: 1. Create a binary tree. 2. Print the tree using “inorder”, “preorder”, and “postorder”. 3. Call a method Count which counts the number of nodes in the tree. 4. Call a method Children which prints the number of children each node has. 5. Inset and delete several nodes according...
You do not need to import the Math class into your Java program to use methods...
You do not need to import the Math class into your Java program to use methods or constants in it. Group of answer choices True False
What are your opinions on plea bargaining? Should this process be allowed to continue or do...
What are your opinions on plea bargaining? Should this process be allowed to continue or do you believe every case should be taken to trial for the actual crime that was committed? Why or why not? Keep in mind the tremendous backlog of cases that already exists.
Write a program that prints the question “Do you wish to continue?” and reads the input....
Write a program that prints the question “Do you wish to continue?” and reads the input. If the user input is “Y”, “Yes”, “YES”, then print out “Continuing”. If the user input is “N” or “No”, “NO” then print out “Quit”. Otherwise, print “Bad Input”. Use logical operators. c++
You are not allowed to import anything • You are not allowed to use slicing •...
You are not allowed to import anything • You are not allowed to use slicing • You are not allowed to use sets or dictionaries • You are not allowed to use any string method • You are not allowed to use anything that hasn’t been covered in class • No built-in function except range() and len() is allowed • From list methods, you are allowed to use .append(), .insert(), .remove() or del. Please do not ask on piazza whether...
What does break and continue mean in C++?
What does break and continue mean in C++?
4 Implement a Java program that meets the following requirements • You can use the Java...
4 Implement a Java program that meets the following requirements • You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant,...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
Please do this in java program. In this assignment you are required to implement the Producer...
Please do this in java program. In this assignment you are required to implement the Producer Consumer Problem . Assume that there is only one Producer and there is only one Consumer. 1. The problem you will be solving is the bounded-buffer producer-consumer problem. You are required to implement this assignment in Java This buffer can hold a fixed number of items. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT