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:
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();
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.
1) Use socket programming (i was able to connect to that ip and port but of no use? how to get data ??)
2) A lot of forums suggest the JNI or JNA way.. which i tried out and accomplished a connection to the port.
But the problem was the appoarch i used in JNA which only supports the loading of C/C++ dll files... not C# dll.... the BioMetric Finger Print device is coded in C#...
So I need to write a program that reads through a String and counts how many vowels there are and prints them out as it finds them. This is what I have so far:
I'm trying to write a program to read the names off of email addresses in a text file and my code is not printing anything to the console. So I want to print everything before the "@" sign. It seems like I'm missing a big thing
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Email { public static void main(String[] args) throws FileNotFoundException, IOException {
I have double checked this code over and over and I just can't find the problem.
What I'm trying to do is take a file and input it into an 2D array.
Ultimately, I should convert the array of integers to an array of characters, then print it out. The file contains a set of ASCII values.
After printing it out, I should then create methods to manipulate the image produced.
Using 2D arrays is a requirement for this exercise.
I think that somehow I'm overcomplicating this and the solution is a lot more simple than I think, but I can't think of what to change.
The error I am getting is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 40 at main.main(main.java:17)
Java Code:
import java.util.*; import java.io.*; public class main { public static void main(String[] args) throws FileNotFoundException { String[][] data = new String[22][40];
I just tried to fill an array with some numbers, calculated by a other function.I just tried to print this array as array, but it doesnt work. Maybe its just about the main method.
public static void main(String[] args) { ggT(5); }
I am creating a hangman game and I want to read in a list of words from a text file, but after the user inputs the name of the text file. I get 'Exception in thread "main" java.lang.NullPointerException'.
Here is the code, where I think the problems lie.
public void runModel(){ ArrayList<String> pirateWordsList = new ArrayList<String>(); System.out.println("What is the name of the file you would like to load? (The file included is called piratewords.txt'"); Scanner in=new Scanner(System.in); String file=in.next(); load(file);
[Code] ....
The full error message is this:
Exception in thread "main" java.lang.NullPointerException at uk.ac.aber.dcs.pirate_hangman.Model.load(Model.jav a:108) at uk.ac.aber.dcs.pirate_hangman.Model.runModel(Model .java:45) at uk.ac.aber.dcs.pirate_hangman.Main.main(Main.java: 6)
I have to write a program for sorting an array of random numbers by the users choice. These random numbers are stored in a text file, which the user inputs, and is then stored into an array for sorting. I won't have a problem with the sorting algorithms, but I've never had to read a text file and store it into an array before
The text file has the numbers stored like so : 148 626 817 4 312 652 643 etc....
I gather that I'll probably have to user the Scanner for the user to input the text file name, but how do I store it to an array? So far I only have the bones of the program done, like so
import java.util.Scanner; public class SortingAlgorithms { public static void main(String[] args) {
I am trying to read in lines of text from a file then prints out the text. I only need one 2D array and can't copy from one array to another.This how the file looks like:
4 4 FILE WITH SOME INFO
I have been able to read the file but when I am trying to run my program I have blank spacing instead of an array.
import java.util.Scanner; import java.io.*; public class Array { public static void main(String[] args) throws IOException{
What is printed is much larger than what I've copy and pasted but I can't post it all here.
The error I get is:
Exception in thread "main" java.io.IOException: Stream closed at java.io.BufferedReader.ensureOpen(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at Map.importMap(Map.java:26) at Map.main(Map.java:44)
package com.arraydemo; import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class ArrayStructures { public long[] theArray; public int arraySize; public ArrayStructures(int size)
I am trying to get this program to take 5 integers from a user and print a bar chart made of asterisks. The only way I've been able to access the values stored in the array is when my loops are nested, but this keeps my output from printing the way I would like it to.
It prints: Enter a number: 2 ** Enter a number...and so on
I want it to take the values say(2,3,5,8,4) and do this: ** *** ***** ******** ****
public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int[] barArray = new int[5]; for(int i =0; i < barArray.length; i++){ System.out.println("Enter a number: "); barArray[i] = in.nextInt(); for(int j = 0; j < barArray[i]; j++){ System.out.print("* "); }System.out.println(""); in.close(); } }
I am simply trying to print out a deck of 54 playing cards. i have organized them in to two separate arrays the first array to place all the image icons the second array to hold the 54 Jlabels. I think my problem lies in the setLayout portion of the program . I also think my image icon path may be wrong?
import javax.swing.*; import java.awt.*; public class CardIconArray extends JFrame { private static final long serialVersionUID = 1L; final public static int numberofcards=54; CardIconArray(){
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
I've to read in an array of 1000 random numbers, and then my program sorts them depending on whether the user chooses bubblesort, selectionsort, etc...My code all works fine, my problem is with the actually output display. I have method that displays the content of the array that I call for the unsorted array, and for the sorted array. So at the moment the output to the user looks like:This program sorts an array of numbers by your choosing.
Array before sorting: 148 626 817 4 312 652 643 134 etc... for 1000 numbers
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it. -createTremor, which will generate the random number as the location and return it.