Given a LISP expression, perform operations on the expression. There will be no list elements that also contain a list such as '(A (B (C D))), which has one atom and one list but the list contains a sublist
INPUT: There will be 5 lines of input. Each line will contain a valid LISP expression. There will be a space between each atom and each list. There are no spaces immediately after or immediately before parentheses in a list. The entire expression must be inputted as a single string.
OUPUT: Perform the given operation on the like numbered expression. The 5 operations are:
1. Print the expression with the list in reverse order. The list will contain only atoms.
2. Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order. The list will contain only atoms.
3 Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order except that singletons are listed as atoms. The list will contain only atoms.
4. Print the expression with the list written with every Nth element deleted and where N is the last element of the list.
5. Print the expression written as 2 expressions where the number of lists in first expression is the last element of the expression.
SAMPLE INPUT SAMPLE OUTPUT
1. '(A B C D) 1. ′(D C B A)
2. '(A A A A B C C A A D E E E E) 2. ′((4 A) (1 B) (2 C) (2 A) (1 D) (4 E))
3. '(A A A A B C C A A D E E E E) 3. ′((4 A) B (2 C) (2 A) D (4 E))
4. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 2) 4. ′((4 A) (2 C) (1 D) 2)
5. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 3) 5. ′((4 A) (1 B) (2 C)) ′((2 A) (1 D) (4 E) 3)
I want a simple jsp page that performs basic operations on numbers such as addition, subtraction, multiplication, division and modulus . How to run that file?
I have some problems about performing regular expression. In the following code, the output as a result is being "valid last name". But in my opinion, it should be "invalid last name". Because "Doe" has not any space, apostroph or any hypen. Look at the regular expression statement: "[a-zA-Z]+([ '-][a-zA-Z]+)*"
package deneme; public class Deneme { public static void main(String[] args) { String lastName = "Mc-Something"; // Mc-Something if(!lastName.matches("[a-zA-Z]+([ '-][a-zA-Z]+)*")) System.out.println("Invalid last name"); else System.out.println("Valid last name"); } }
I know that the asterisk qualifier means character(s) in any number.(Is this wrong?) So for "Mc-Something", 'M' corresponds to [a-zA-Z], 'c' corresponds to +, - corresponds to [ '-], 'S' corresponds to [a-zA-Z], "o" corresponds to +, and finally "mething" corresponds to *, doesn't they? But for "Doe", there is no any space, apostroph or hypen.
This may be a multipart question. Basically I have to write a program that accepts a string, converts it to a double splits it and then performs a calculation.
public static void main(String[] args) { String input = ""; // initalize the string boolean isOn = true; // used for the while loop...when false, the program will exit. String exitCommand = "Exit"; // exit command String[] token = input.split(("(?<=[-+*/])|(?=[-+*/])"));
[Code] ....
This is the error I get:
Enter a math problemException in thread "main" java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1842) at sun.misc.FloatingDecimal.parseDouble(FloatingDecim al.java:110) at java.lang.Double.parseDouble(Double.java:538) at Calculator.main(Calculator.java:22)
[Code] .....
How do I go about actually fixing it. Without that line commented out I get this:
Enter a math problem 2+2 <-What I entered [Ljava.lang.String;@135fbaa4
Also, how would I go about using the submethods to check for valid operands and operators (also part of the problem) I have the actual lists made obviously, but am unsure how to get those to work with the problem.
importjava.util.Scanner; public class ManageAccounts {
[Code].....
and i need to create a .dat file and have it perform the tasks it states, what to do, I've just been looking for existing codes and trying to modify them because i have a very limited knowledge of programming.
I am new Java Programming and I am struggling to pass my Java class. How to perform Java but I am trying. For this particular assignment I supposed to:
* Change all variables' data types to double. * Change the two prompts to request double values * Change change the two calls to the nextInt() method to nextDouble().
This is the original assignment:
import java.util.Scanner; public class ArithmeticDemo { public static void main(String[] args) { Scanner input= new Scanner(System.in); int firstNumber; int secondNumber; int sum; int difference; int average;
I've created several methods in another class to perform certain matrix calculations. Do I need to have mutator method in this calculation class to define the column length of the matrix object? I understand why the following code is not working, but I was hoping to get a quick and easy workaround. I'm not sure how to initialize the size of the column for newMatrix within the method.
public int [][] sum(int matrixOne[][], int matrixTwo[][]) { int sumMatrix [][] = new int[matrixOne.length]["WHAT TO PUT HERE"]; for (int i = 0; i < matrixOne.length; i++) { for (int j = 0; j < matrixOne[i].length; j++) { sumMatrix[i][j] = matrixOne[i][j] + matrixTwo[i][j]; System.out.println("matrixSum" + sumMatrix[i][j]); } } return sumMatrix; }
Then I will use this method to print the new matrix:
public void printMatrix(int newMatrix [][]) { for (int i = 0; i < newMatrix.length; i++) { for (int j = 0; j < newMatrix[i].length; j++) { System.out.print(newMatrix[i][j] + " "); } System.out.println(""); } }
Is all of this overkill and should I just define all the methods within the same class to avoid these issues?
How do I create an instance of a class in a method?
I am a bit rusty whenever I think of instances. I always think of main method and objects when I see instance which gets me confused on what to do when I am not in a main method. The example:
I have a abstract class, School, and inside School I have some methods that must preform some action on an instance. For example, there is a move() method that must move the instance of School. Another method named, personOld(), which returns whether or not an instance of School surpassed some determined age.
How do I keep an item (TreeItem) from being selected when performing a drag -n- drop? I don't want it to be selected because it will end up making the target disappear (selection of TreeItem changes target panel).
Related question: Is there a way to "veto" a tree selection change as well?
I have in my application a button that when it is pressed, runs a long running task (usually takes a couple of seconds....).
My problem is that while the task runs, I want to stop the button from receiving clicks. Unfortunately this is something I have not achieved.
I have tried creating a new thread and calling the long running method, and using the Display.geCurrent().asyncExec...
Examples of what I have tried so far:
myButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (myList.size() > 0) { myButton.setEnabled(false); myButton.setGrayed(true);
[Code] .....
In both cases, while the button is disabled and the cursor busy, if the user clicks the button, the long running method is ran several times - and this is what I want to avoid.
I have having some trouble on counting the primitive operations on the pseudocode given below:
Algorithm 4. MaximumArray(Arr) Input: A 1-D numerical array Arr of size n 1) Let CurrentMax = a0 2) For i = 1 to n-1 3)If ai > CurrentMax Then CurrentMax = ai 4) End For Output: CurrentMax, the largest value in Arr
As of now, I know that for Line 1 there are 2 operations (one set and one read). I don't know how to figure out the for loop and If statement (line 2 and line 3 too).
I've been wondering about this for a while. Is there any way to parallel I/O operations or is this a bad idea? If you could create two lists of good and bad ways to parallelize I/O.
I am working on implementing a stack using a linked list. Programming the stack operations (push, pop, isEmpty, etc.) was easy but my directions were to provide the user with a menu to choose the operation that he/she wishes to perform. I am new to JFrames/Menus so how to make the stack operations available in a menu.
This is what I have so far, but I don't know how to continue:
import java.util.Scanner; public class ArithmeticComputation{ public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int num1 = stdin.nextInt();
[Code] ....
I'm looking for a method that allows me to assign char into actual operators, so that I can loop through all the computation.
String filename="C:UsersRajashekarDesktopfwfwdSoftware Failures1_Test.txt";//Input Files String data; public ArrayList<String> value=new ArrayList<String>(); public void read() throws IOException{ File f = new File(filename);
I have read that when two threads have two steps (of execution) and each step involves many operations, then the operations of both the threads kind of overlap one-another. For example
I think I am not very clear about interleaving actions/operations? Especially when we say that atomic actions can not be interleaved. But
Java Code:
class Counter{ private int c=0; void increment () { c++; } void readIn () {
[Code] ....
And the following sequence of events occurs.
Thread A: Retrieve cThread A: Increment cThread A: Store the result in cThread B: Ask the user to enter a valueThread B: Read in the value, store it in c
Now the value of c obtained after increment will be lost (Thread Interference). Isn't this an example of interleaving operations?
i've spend an hour or two, pasting fragments from tutorials and nothing changed.
Well - i have GUI, that have JComboBox with two elements: String[] fedoras = { "Fedora 19", "Fedora 20" }; JComboBox fedora_list = new JComboBox(fedoras); fedora_list.setSelectedIndex(0); fedora_list.setBounds(120,170, 170,25); fedora_list.addActionListener(this); this.add(fedora_list);
Below i have normal button (named Update) with "update" set as ActionCommand. This button after clicked should check which value from list is selected and perform different operations for that elements. But it's harder than i thought.
Code for update button:
public void actionPerformed(ActionEvent e){ String cmd = e.getActionCommand(); (...) else if ("update".equals(cmd)){ String selectedFedora = (String) fedora_list.getSelectedItem(); if (selectedFedora.equals("Fedora 19")) {
[code]....
- after user clicked Update button, button should check which value is selected in JComboBox (fedora_list). - if Fedora 19 is selected and button clicked, then action in Xterm - if Fedora 20 is selected, this same action in Xterm is performed, but for Fedora Linux 20
The problem is - i don't know hot to code Update button to check which value from fedora_list (JComboBox) is selected and perform other actions for every element on List.
How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)
Example : Addition, Subtraction, Multiplication, Division.
The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.
The program i am working on is to take string from the user which should be a phone number then it will return true or false based upon the method that checks to see if it meets the criteria of a certain format if does not it will return false otherwise return true. I am working on a if/else structure that will print this number is valid if it meets the criteria of the method i previously mentioned or return the number is not valid if it is false. the logic of the expression i put in the parentheses of the if/else statement. This is what i have so far:
if(){ System.out.println("The phone number is valid"); } else { System.out.println("This isn't a valid phone number"); }
Do i need to compare it based upon the method that checks if it is true?