Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to find subarray from given large 2d array of arbritary dimension
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Raghav Purankar
how to find subarray from given large 2d array of arbritary dimension
0 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


my code is: import java.lang.*; import java.io.*; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class SubMatrix { public static void main(String[] args) throws IOException {

    File file = new File("file1.txt");
    List<float[]> list = new ArrayList<float[]>();
   Scanner scanner = new Scanner(file).useDelimiter("\n");



    while (scanner.hasNext()) {     
        String[] values = scanner.next().trim().split(" "); 
         float[] floats = new float[values.length];
         for (int i = 0; i < values.length; i++) {
             floats[i] = Float.parseFloat(values[i]);
             }
             list.add(floats);
             } 
             float[][] values = new float[list.size()][];
             for (int i = 0; i < list.size(); i++) {
                 values[i] = list.get(i);
                 for (int j = 0; j < values[i].length; j++) {
                     System.out.print(values[i][j] + " ");

                     }
                     System.out.println();
             }


              int row =values.length;
             int col=values[0].length;

//*******************************

              int subrow;
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter the number for rows :");
            subrow = Integer.parseInt(br.readLine());


             double subArray[][] = new double[subrow][col];

             for(int k=0;k<subrow;k++){
                 for(int p=0;p<col;p++){

             System.arraycopy(values,0,subArray,0,subrow);
             System.out.print(subArray[k][p] + " ");
                 }
                 System.out.println();
             }


}}

and .txt file is: 1.0 3.1 2.1 3.4
2.4 2.0 4.6 5.1
0.2 3.3 4.7 9.1
4.0 5.4 5.1 3.2
6.1 2.1 6.4 2.6
1.2 2.0 3.5 6.9
3.1 2.5 4.6 9.8
7.1 8.1 9.4 5.1
12.1 3.1 2.5 2.4
3.8 9.1 2.1 6.7

i want to print the subarray of any dimension from given array file. i have tried upto above code but it gives runtime error as: NumberFormatException:empty string. error might be on "floats[i] = Float.parseFloat(values[i]); " line.help wud be apprec.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
how to find subarray from given large 2d array of arbritary dimension
how to find subarray from given large 2d array of arbritary dimension ... to print the subarray of any dimension from given array file. i have tried upto...(br.readLine()); double subArray[][] = new double[subrow][col
how to print the content of file in 2d matrix having same dimension as given in file(n*m).
how to print the content of file in 2d matrix having same dimension as given in file(n*m).   here is code: import java.io.File; import... of any dimensions in the form of 2d n*m matrix. pls help me
Advertisements
array find all possible dimension
array find all possible dimension  Given array: int[] dimension = { 1, 2, 3 }; That produces the output: 1 2 3 12 13 23 123 I'm new to array...i can't figure out the way on even how to start... any idea?...really appreaciate
how to find inverse of n*n 2d array in java
how to find inverse of n*n 2d array in java  I reached upto code of printing the matrix as: Assume that matrix is square matrix where row=column code is: public class ReadContents{ public static void main(String args
how to create unit matrix in java of arbritary dimensions
how to create unit matrix in java of arbritary dimensions  i want to create the unit matrix of arbritary dimensions say (n*m).i m a new beginner to java.someone having the program for that? help would be appreciable
how to find the given date is sunday
how to find the given date is sunday  how to find the given date is sunday in java?   Hi Friend, Try the following code: import java.util.*; import java.text.*; class CheckDay{ public static void main(String
Find a missing element from array
Find a missing element from array We have two arrays A and B where B consists... the array B. From these two arrays, we have to find the missing element from the second array i.e from B. For this, we have calculated the sum of elements from both
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
Find Second Largest Number from an Array
Find Second Largest Number from an Array This section illustrates you how to find the second largest number from an array. For this purpose, we have allowed... among them. Pulls the largest number out from the array and again check
Find Array element from index using GUI
Find Array element from index using GUI In this tutorial, you will learn how to create an GUI application to find an array element from its index. For this, we have created an an array of 100 randomly chosen integers and allow
JavaScript array dimension
JavaScript array dimension       In this code we help you to understand array dimension... to make a Two dimension array. The page on loading invoke a function display
Selecting elements of 2D array with GUI
Selecting elements of 2D array with GUI  Hello! I am building... or selected elements of below 2D array (images attached): Year Season 2002 2003... how start with the code for displaying elements of the array selected by user
how to print the average of each column of 2d n*m array using java
how to print the average of each column of 2d n*m array using java  here is my code: import java.io.File; import java.io.IOException; import... in the given file having say n*m matrix.   import java.io.File; import
Storing the Color Image pixel values into 2d array
Storing the Color Image pixel values into 2d array  i want to store the color image pixel values into 2d array and agiain the array have to store into a text file using java... plz provide the code
how to find last day 0f any given month in mysql?
how to find last day 0f any given month in mysql?  how to find last day of any given month in mysql?   Hi Friend, Here is required code: DECLARE @dtDate DATETIME SET @dtDate = '8/18/2007' SELECT DATEADD(s,-1,DATEADD
Find position of an array element
Find position of an array element In this section, you will learn how to find the index of an array element. For this, we have allowed the user to enter... the position of the given integer in array. If the given integer is not in the array
PHP Array get key from value
In php array one can get the key from value by the use of array_search function Array_search function searches the key for the given values in the array. Example of PHP Array Get Key from Value <?php $product=array
Read text file to 2D array and sorting the second column
Read text file to 2D array and sorting the second column  we found... and the second column is marks in tests.What we need to find is which student marks... find what was their average % decreased. Then take top 5 of those and write
sql php array
; SQL PHP Array support simple dimension array. The SQL PHP Array is used to populate array from MySQL database. Understand with Example  The Tutorial illustrate an example from 'SQL PHP Array'. To understand and grasp
find the given input is integer or string
find the given input is integer or string  simple coding for to check the given input value is integer or no.If the given value is integer display "Value is integer" otherwise "Value is not a integer"?   class
code to display images using 2d array - Swing AWT
code to display images using 2d array  HI !! I have an image file in ascii/binary format (lines & pixels) in the form of a 2d-array. I would like... such requirements. Can anyone please tell me how to go about it ? Explanation of the code
Find out last character of array
Find out last character of array  How we can find out the last character of array in java program
2d arrays
2d arrays  what is the code for multiplying the values in a 2d array and printing out their sum
php array delete element
Array element can be deleted by the array_splice() function. array_splice removes the element starting from given index with the given length. Length is optional.If not given all elements get removed PHP Array Delete Element
How to Print Array in JavaScript
How to Print Array in JavaScript In this section you will learn about Array in JavaScript. Array are important part of all programming languages. Array...;; There are some methods of array that can use in array like length() can find
How to get given index value from FloatBuffer in java.
How to get given index value from FloatBuffer in java.  In this tutorial, we will discuss how to get given index value from FloatBuffer in java...; The allocate(...) method create a new float buffer of  given capacity
How to read data dynamically from keyboard to array in flex
How to read data dynamically from keyboard to array in flex  How to read data dynamically from keyboard to array in flex
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
java 2d graphics - Java Beginners
java 2d graphics  Hello All I need to use 2d graphics in java to build up a map from the given geographic coordinates. What i am not getting is how to scale down these geographic coordinates to device coordinates. I would
How to upload a large excel file - JSP-Servlet
How to upload a large excel file   Dear sir , How to upload a large excel file and how to read a that large excel file or how to get a each column values from that large excel file.For small file i am getting values
Advertisements
 

 

 

DMCA.com