Write a program to reverse sentences (demarked by a period) in a paragraph (demarked by an empty line input from the console) using any list of your choice.13. Create a vector that stores N numbers.
i need to reverse sentences in a paragraph.the sentences end with a period and the paragraph ends with a newline.
i tried to construct Vector<String> and Vector<Vector> reading input from scanner, but that didn't work because scanner skips newlines.
I'm really trying to understand an example on how to construct a good suffix table for a given pattern. I've looked at numerous examples, but do not know where the numbers come from.
So here goes: The following example is a demonstration of how to construct a Good Suffix Table given the pattern ANPANMAN:
In this i Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/). For instance the expression: (1 + 2) * 3 can be represented by the following tree:
I Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/).
For instance the expression: (1 + 2) * 3 can be represented by the following tree:
But when i Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder so how to solve these error
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import javax.swing.tree.TreeNode; public class InToPost { private static String str;
How do I pass the data within an initialized array from inside one method to another method of the same class? Will I need to return the array, assigning it to a temp array, which will then be passed as an argument to the other array? The idea is to create an array for an entire year, and be able to manipulate or edit data for a particular month using the other method.
public class Temperature { static Scanner input = new Scanner(System.in); static String [] monthArray = {"January", "February", "March", "April", "May", "June", "July", "August", "October", "November", "December"}; public static void main(String[] args) {
I want to keep count of how many students are in my array. the array i made up of objects from other classes. like the class Student how do i do this. i have tried contains but better way it to to a loop to go through the array and determine if each object is a particular type but i don't know how to do this. here is the code
import java.util.*; import java.util.ArrayList; public class Driver { public static void main(String[] args){ /* Comments required PersonFileReader pfr = new PersonFileReader("person.dat"); ArrayList<Person> testData = pfr.readData(); Database db = new Database(testData);
the problem I'm having is I want to use a mutator method to set data for an array element. The code I have so far is:
public void addProduct(String productName) //Goes through and sets the name of a product and assigns it to the array { int index; for (index = 0; index < product.length(); index++) { product[index].setName(productName); numberOfProducts++; } }
The array was initialised like this:
Product[] product = new Product[3];
And the setName(String) method is just your typical mutator method.However, in Eclipse, I have an error messages. It is:
"-The method setName(String[]) is undefined for the type String" .....
I can read the data to a monitor perfectly. But, I'm having problem reading data from an external file into an array of class objects. Here's my attempt at writing the method:
private void openFile() //This method asks the user to enter a file name(including the file extension) and then //Sets the data to an array of Product type { String fileName, storeName="", emptyLine1="", emptyLine2="", name="", productName=""; int demandRate=0; double setupCost=0.0, unitCost=0.0, inventoryCost=0, sellingPrice=0; Scanner inputStream = null;
I am working on a simple JAVA tutorial, not homework, where employee data is taken from an array and displayed on the console. The data is divided by department, age, name and for the Accounting and Information Systems departments, they are displayed in ascending order by employee age. Everything works except I am not getting the output to the console other than the titles. As I step through the debug, the data clearly is populating the array.
package SimpleJavaAssignment; import java.math.*; public class PrimeAgeChecker { public boolean PrimeAgeChecker(int age) { BigInteger bi = new BigInteger(String.valueOf(age)); boolean prime = bi.isProbablePrime(10); return prime; } }
I set the limit to 2 so the producer blocks after two insertions until an item is consumed. Because we are dealing with a basic counter that increments, we do not lose any data. Since after queue is freed up we simply increment by 1, so we are able to store all numbers. However, in real world situation, you might be storing data coming from redis server into the queue. And redis server may be publishing a plethora of data. So when the queue blocks, and new data comes in, what happens? Is the currently blocked data lost forever and the new data that came in is now blocked, or is the new data that came in ignored and the old data remains being blocked until queue is freed up?
Java Code:
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class BlockingQueueBlocking { private BlockingQueue<Integer> sQueue = new ArrayBlockingQueue<Integer>(2); int counter=0; private void test() throws InterruptedException{
My assignment was to create a class and then write a program that uses the methods of the class I created. All the output is correct except for the Question # Missed. It prints [I@1dd0fe7. The wrong question numbers have to be stored into an array and that array printed. I've tried using a for loop to print, rearranging the code, setting the code to how I did in the other methods. I either get this [I@1dd0fe7 -or- a bunch of 0's. I'm not sure if I am calling the method incorrectly, or just do not have the correct set-up to print the array, or if I am just not grabbing the ones that are incorrect.
public class DriverExam { // Fields private boolean result; private int testTotal; private int numWrong; private int [] numMissed; private char [] answerKey;
TL,DR: observe the nodes just below, that is the data each node in the link list contains. How do I iterate through the entire list to reach the last element (H), so I can add an element right after it?
So I have 4 nodes doubly linked with two dummy nodes for head and tail:
Ok, so since the list only contains 8 elements that are not null, its size is actually 8 correct? So now lets say I have an add method that has
add(E item) and inserts the item at the end of the list. So I can get to the last node with tail.previous(), but then how do I iterate to the end so I can add the item after the last item in the list (H). I guess I don't know how you only access one nodes data when that data is an array with empty spaces.
Here is the entire Node code:
Also, I can't just iterate through the whole thing because I am not supposed to. I am supposed to just find the right node and iterate through that only.how to maneuver around a linked list containing nodes where each node contains an array.
/** * Node class that makes up a DoublingList. Feel free to add methods / * constructors / variables you might find useful in here. */ public class Node<E> {
/** * The node that comes after this one in the list
So I want to write a constructor that creates a new object with the data from the array values. I don't know where to start. It's the last method in the code:
public class Measurements { private double[] values; private double[] newArray; private int n; //numberofvalues private double[] ms; public Measurements(int max) { //constructor
I'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).
Java Code:
class ArrToMain { public static void main(String[] args) { final int NUMBER_OF_ELEMENTS = 1000; double[] numbers = new double [NUMBER_OF_ELEMENTS]; //Invoke initialize method initialize(numbers);
public class InputFileData { /** * @param inputFile a file giving the data for an electronic * equipment supplier’s product range * @return an array of product details * @throws IOException */ public static Product [] readProductDataFile(File inputFile) throws IOException{ // YOUR CODE HERE }
This code is meant to be used to read a text file and store the data in an array of type Product[]. I know how to read in a text file and have it sort it into an array, but I've never seen code laid out in this fashion before (specifically "public static Product[]", and I'm unsure how to work with "(File inputfile)". I've looked all over the place but can't find any examples of anything like this.
Also, the code given cannot be changed, as it's that code I have to work with.
I still don't understand how to use it as a whole. For example, do I read the file in the main and have this method read that in and output to the Product class? Do I read the file in this method? I can't work out how to make this work when I have to use this method.
I'm trying to figure out the necessary code for reading integers from a text file, then placing them withing the two-dimensional array I have created, and then finally printing the array using a nested for-loop. I have attached the file I would like to read from. I'm having trouble figuring out how to reference the text file with the integers, and also how to properly create a dynamic preface for each row of the array. I want the preface to display as "Week #: ", with # being the row number. I tried to create an integer to be used that way, but NetBeans tells me whatever integer I declare has already been defined in method main. I know I need to use scanner to read the file. I would like the output to display like this:
Conditions : Need to print all the inputted data(name,score) and the average.
import java.util.Scanner; public class Case2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] score = new int[5]; String[] name = new String[5]; int ave = 0;
/** * Compute shortest paths in a graph. * * Your constructor should compute the actual shortest paths and maintain all the information needed to reconstruct them. The returnPath() function should use this information to return the appropriate path of edge ID's from the start to the given end. * * Note that the start and end ID's should be mapped to vertices using the graph's get() function. */ class ShortestPaths { Multigraph graph; final int INF = Integer.MAX_VALUE; PriorityQueue<Integer> Q;
[Code] ....
I followed someone else psuedocode very closely but for whatever reason, my edge[] array is just full of null data, which means I can't actually return the shortest path. Why that's happening/how to fix it? Maybe I'm not understanding dijstra's correctly.
I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code
import java.io.*; import java.util.*; public class prog464aStoringLargestNums { public static void main(String[] args)
I have to make two classes. The first one crates an instance of an array of several integers and prints data (average, greatest, lowest, et cetera) based on the second class, which contains the methods. I'm having a problem with the syntax for the first class required to use the methods.
Here's a shortened version of what I have right now just based on processing the number of integers in the array (because if I can get just one method properly connected, I could figure out everything else).
Driver
import java.util.Arrays; public class ArrayMethodsDriver { //Creates the ArrayMethods object public static void main(String[] args) { int[] a = {7,8,8,3,4,9,8,7};
[Code] ....
When I try to compile this, I currently get the "class expected" error on the count part.