Read Picture And Print Out Number Of Blocks - Counting In Multidimensional Array
Dec 19, 2014
I have to write a program that will read a picture and then print out the number of blocks inside it.
I have to read the picture as a binary matrix of the size r - c (number of rows times number of columns). The blocks are groups of one or more adjacent elements with the value 1.
- Blocks are built exclusively of elements with value 1
- Each element with value 1 is a part of some block
- Adjacent elements with value 1 belong to the same molecule.
We only take into account the horizontal and vertical adjacency but not diagonal.
INPUT:
In the first line of the input we have the integers r and c, separated with one space.
Then we have the r lines, where each contains s 0's and 1's.
The numbers inside the individual lines are NOT separated by spaces.
The OUTPUT only print the number of blocks in the picture.
import java.util.Scanner;
class Blocks{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
char ch[][];
int rowNum=sc.nextInt();
int columnNum=sc.nextInt();
I have to write a program that will read a picture and then print out the number of blocks inside it.I have to read the picture as a binary matrix of the size r c (number of rows times number of columns).The blocks are groups of one or more adjacent elements with the value 1.
- Blocks are built exclusively of elements with value 1 -Each element with value 1 is a part of some block -Adjacent elements with value 1 belong to the same molecule.
We only take into account the horizontal and vertical adjacency but not diagonal.
INPUT:
In the first line of the input we have the integers r and c, separated with one space. Then we have the r lines, where each contains s 0's and 1's.The numbers inside the individual lines are NOT separated by spaces.The OUTPUT only print the number of blocks in the picture.
I just started in java programming and into Arrays multidimensional. I started a simple 2 dimensional array with 5 names with genders. I 'm having issues because it does not want to print out the names with correct genders Male/ Female. The simple program should print out the 5 names with gender type.
example:
Jack - Male Sally - Female Dave - Male Sue - Female Brian - Male
Here is what I came up with so far:
public class Multiname { public static void main(String[] args) { //String[][] multiname; String [][] multiname =
[Code] .....
This is the result:
multiname : Jack multiname : sally multiname : Dave multiname : Brian multiname : Sue
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at MultiD.main(MultiD.java:29)
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
Designed to store a first name (string), last name (string), and zip (int). Assume each line will contain two strings followed by integer each separated by tab. Then print.
I have my two class files (one for the individual and one for the array) and then my driver below. I think my only problem is my driver. I think I'm reading the data file wrong but not sure how exactly.
The point of this program is to read characters from a txt file and store them into a 2D array. After this has been accomplished, the information is to be printed in the same manner it is read from in the txt file.
Here is the code I have so far:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException
[Code] ....
And this is the error I am receiving when trying to accomplish the goal of the project:
Exception in thread "main" java.lang.NumberFormatException: For input string: "############" at java.lang.NumberFormatException.forInputString(Unk nown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Maze.<init>(Maze.java:15) at Main.main(Main.java:20)
What's going on here and how I can correct this?? The information I am trying to store in a 2D array and then print is this:
My assignment is to write some code that will multiply every number in an array by 2 and print it out. This is using a site zyante which is a interactive online book kind of thing.
I have tried For (i=0; I < 8; i++) with like userVals = userVals * 2) }
And it doesn't like that so i'm guessing i am no where close to right. The chapter doesn't give me any example of doing anything close to this so i am completely lost on what i have to do.
This is the program :
import java.util.Scanner; public class NegativeToZero { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_ELEMENTS = 8; // Number of elements
I wrote this code which print a black image depends on the number of rows and columns you give it
public class BlackImg { private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors. // no need for showing the class here. // so i created here an array of type Mycolor, for example: // { {(255,255,255), {(127,127,0)} }
[Code] .....
my problem is that my output comes good except the last line ,
Output: (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) BlackImg@1db9742 //what is this line , why does it showing up ?
New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows
(1) The original list of N numbers from the input file, (2) The original list of N numbers printed in reverse order of how they appear in the input file. (3) The sum and average of these numbers, (4) The minimum of all the numbers, (5) The maximum of all the numbers.
At the bottom of this code snippet you will see the print statement. I am trying to divide the multidimensional array by its sum. Can this be done simply in the System.out statement, or do I need a separate method?
private static void Histogram() throws IOException { int[][][] ch = new int[4][4][4]; /* 4 for 64 and 8 bins, 8 for 512 bins */ BufferedImage image = ImageIO.read(new File("airplane_training1.jpg")); for(int x = 0; x < image.getWidth(); x++) for(int y = 0; y < image.getHeight(); y++) {
The method public static int steps(int posts, int stride) calculates how many strides can be taken to get back to posts. Let's say if the method is (12, 4), it takes only three steps. Now let's say the method has parameters (12,5), so it should be (5, 10, 3, 8, 1, 6, 11, 4, 9, 2, 7, 12). My method works for such examplse as (12, 4) or (12,3) or (6,2)... but how can I figure out (12,5)?
Java Code:
public static int steps(int posts, int stride) { int countSteps = 0; int result = 0; do { result += stride;
import java.util.Scanner; public class ColumnSum { public static void main(String[] args) { Scanner s = new Scanner (System.in); int userpick = 0; int sum = 0; int [][] matrix = {{5, 9, 87, 74, 12, 7}, // row 1
[code]...
Right now my code gets all the numbers in a row and adds those up, but I want it to get the numbers in a column and add them instead. The problem is I don't know how to get the userpick (the number that the user picks to determine which column gets added) to be set to that particular column.
I come to the point: I just started to learn java through various manuals and in one of them I came across a declaration of an array that I do not understand:
int[][] multiArr = new int[2][];
the manual says that you can allocate the multidimensional array multiArr by defining size in only the first square bracket but I can't undestand how you can use this array. Seems to be no way to store data with it!
public class StuTest { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args){ int[][] testScores; // [students][tests] String[] stuNames;
[Code] ....
The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. For my "printTestReport" method, I have to calculate the average of the test by test number.
I've found different examples on line, but none that use the split method with a multidimensional array. I would like a user to input coordinates (x,y) for city locations and store them into a 2-D array. For the user to input the x,y-coordinates on one line I need to use split(',') and then parse the string array to a double which will then be used to calculate the distances from one another.
My issue is how to store the String vales into the 2-D array. I do not want to store the x-value at even (cityArray[0]) and y-value at odd (cityArray[1]) 1-D locations.
String temp = "hi this sf hello is new what is this"; String[] cmd = temp.split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
However, when i get the input from user , i didnt get the expected result:
Java Code:
System.out.println("Enter the input string to count the words: "); String[] cmd = new Scanner(System.in).next().trim().split("s"); int num = cmd.length; System.out.println("number of words are: "+num); mh_sh_highlight_all('java');
I need to modify modules used in the book that run a bubble sort, selection sort, and insertion sort on an integer array such that each module keeps a count of the number of swaps it makes.
How do I code for this?
Then we have to design an application that uses 3 identical arrays of at least 20 integers. That calls each module on a different array, and display the number swaps made by each algorithm.