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...
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.
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...
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...
What does break and continue mean in C++?
What does break and continue mean in C++?
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...
Complete all parts of this java program. Use Homework2Driver.java below for testing. /* Note: Do not...
Complete all parts of this java program. Use Homework2Driver.java below for testing. /* Note: Do not add any additional methods, attributes. Do not modify the given part of the program. Run your program against the provided Homework2Driver.java for requirements. */ public class Node<T> { private T info; private Node nextLink; public Node(T info) { } public void setInfo(T info) { } public void setNextLink(Node nextNode) { } public T getInfo() { } public Node getNextLink() { } } /* Note:...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread prints all capital letters 'A' to'Z'. The other thread prints all odd numbers from 1 to 21.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT