That actually is the full problem description. Here's the link for more examples:
http://codingbat.com/prob/p155405
I fixed the issue though. Like the quote above had stated, endpoint was greater than beginpoint so I had to fix that. The idea of 'subarray' was more or less just parts of the...
Homework Statement
Given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups).
Homework Equations
The Attempt at a Solution
public int[] squareUp(int n) {
int length = n*n;
int[]...
it is for a class, and unfortunately my freedom for how I solve the homework is limited.
I have actually done what you stated before where it reads the file line by line, however I have a question.
Say I have a condition:
if [ substring is found in line i, col 10-15 ]
then
variable +=...
Homework Statement
Say I have a textfile that is separated by columns, and I want to search columns 10-15. If there are any matches, then I want to cut out specific parts of all the matches and print it to the user. How do I do this?
Homework Equations
The Attempt at a Solution
What I...
Thanks for the clarity. Bash feels a lot different to wrap my head around than with today's systems.
Just curious as well, say I have a textfile(list of medications and their info for example) that contains some information. If I do this:
medDoses=$(cut -f3 <medFile.txt>)
Would medDoses be...
Homework Statement
so I have this text file that I'm reading line by line
and here is an example of a line:
root pts/1 01-19 13:41 (10.0.0.48)
Homework Equations
The Attempt at a Solution
How can I extract the terminal and timeframe only?
I tried
echo $line | cut -d : -f2, 4...
UNIX and bash shell. Someone had guided me there from unix.stackexchange.
Although I'm feeling a lot more confident now, found a couple online tutorials that are great
I actually found it in /etc/skell/. It sucks because I have several books and they all point to different things; It's not a very uniform platform for me :(.
I simply added in echo$(user) and it worked.
if you have a book similar to C by brian and ritchie I'm all ears - I have unix shell...
Homework Statement
I'm playing around in UNIX and I wanted to modify my .profile file in my home directory, but It's not there. I know you type in ls -a to view the hidden files but it's simply not there. Do I just create one? I want it to just display my name every time i log in.
Homework...
It was meant to prevent it from going out of bounds by only having it go through the second for loop as many times as it could(but clearly it does not achieve this, now I notice)
Here is the new code that works!:
public int countClumps(int[] nums) {
int length = nums.length;
boolean...
Homework Statement
Say that a "clump" in an array is a series of 2 or more adjacent elements of the same value. Return the number of clumps in the given array.
countClumps([1, 2, 2, 3, 4, 4]) → 2
countClumps([1, 1, 2, 1, 1]) → 2
countClumps([1, 1, 1, 1, 1]) → 1
Homework Equations
The logic is...
Homework Statement
Given a string and a non-empty word string, return a string made of each char just before and just after every appearance of the word in the string. Ignore cases where there is no char before or after the word, and a char may be included twice if it is between two words...
Is the bolded a hint ? Since arrays are of fixed lengths. I was just thinking as I was doing these challenges that writing a bunch of if statements felt a little too trivial and not challenging...
Homework Statement
Given 2 int arrays, a and b, of any length, return a new array with the first element of each array. If either array is length 0, ignore that array.
front11([1, 2, 3], [7, 9, 8]) → [1, 7]
front11([1], [2]) → [1, 2]
front11([1, 7], []) → [1]
Homework Equations
The Attempt...
group += org.toString()
this line will access the x and y positions of the movable objects inside group.
Edit: made a misunderstanding. Since group is just an arraylist of movable objects, organisms can be stored into the group object. Essentially I thought any movable object inside group had...
Homework Statement
package movable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author
*/
public class Group implements Movable {
private final List<Movable> groups = new ArrayList<Movable>();
public void addToGroup(Movable movable) {
groups.add(movable);
}
@Override
public...
If it matters all I changed was instead of having the arraylist of person retainall the elements from entry.getValue() (I'm assuming this shouldn't work because it's just an object, not a list structure) i had simply added them into the arraylist if the condition was fulfilled.
Then I...
Homework Statement
Essentially, I am expected to have a method that can do a keyword search through my hashmap and return respective results. My hashmap is as follows:
HashMap<String, Person> phonebook
The string as a key is generally the name of the entry. A person object has 3 fields(Name...
Homework Statement
public class BinarySearch {
public static boolean search(int[] array, int searchedValue) {
int beginning = 0;
int end = array.length - 1;
while (beginning <= end) {
int middle = (beginning + end) / 2;
if (array[middle] ==...
I apologize I didn't see your entire message from earlier, and no I have not used switch statements yet. But I do know the general idea behind them from working with C and I don't see any reason why he shouldn't permit me to use them. The JUnit is a test that just runs random values into my code...
The deadline to hand in this lab was extended to this Saturday as apparently I'm not the only one who was having difficulties(poorly designed lab? :D) With that being said, is there any way I can benefit off of comprehending the JUnit test that my professor uses to grade our labs? My current lab...
Hmm... would writing more conditions alleviate this issue? Or would that be considered inefficient to do? I'm not too comfortable with java's syntax yet so I'm not sure.
Ah, I see. So what i can do is write another else if checking if the other cards match? SOmething like:
for (int i = 0; i < hand.length(); i = i + 2) {
if (hand.charAt(0) == hand.charAt(2)) {
r = hand.charAt(0);
} else if (hand.charAt(2) ==...
In regards to the four of the kind, I'm a bit confused. It says that the suit is irrelevant so wouldn't I just have it check at every index seeing if they share the same char?(In this case, start at 0 and work my way up to 8)
And then of which it would check if the counter is at 4 and proceed to...
Homework Statement
Hi, so I'm working on a project(part 1) where I am supposed to create a simple card game, under a few requirements.
Here are the requirements:
1. Write a method boolean hasFlush(String hand) that checks whether the five-card poker hand given as 10-character string is a...
Hmm, tbh I don't actually quite understand myself either. But for that matter, maybe this is an example.
/**
* BankAccount class, foundational code.
*
* @daniel
* @9/21/2016
*/
public class BankAccount {
double balance;
/**
* Constructor for objects of class BankAccount...
I see. That's relatively simple and I just hope he won't deduct marks for using syntax that wasn't demonstrated by him(He just briefly went over everything a beginner Java user should know by the end of the course). I think the main goal of this assignment is to simply return values from methods...
Thanks for the response. Whilst it would be a relatively easy task for me to do this, the fact of the matter is the professor hasn't really gone into detail... about anything. He hasn't taught any of java's syntax or methods or really anything aside from general theory. Which is why I'm unsure...
If this helps... this is part 2 of the lab. I'm used to having sample inputs/outputs so I know what is expected of me but I was not given anything here.
1. Write a class Rectangle that has two double fields width and height, and a method void setDimensions(double w, double h) that...
Homework Statement
[/B]
So my professor has given this as a lab activity. He has not given any sample outputs, other than these simple instructions. I don't actually understand to what extent I'm to perform this activity to.
Write a class BankAccount that contains a double field balance, and...
Homework Statement
Hi, I have a piece of code that I'm trying to comprehend but I don't understand some aspects. Here is that code:
#include <stdio.h>
/* function prototype declaration for FindSum */
void FindSum(int, int, int *);
int main(void)
{
int a=2, b=5, c=1, x=3, y=4, z=7;
/*...
I am really enjoying it right now, as I feel like I am understanding a lot more about the computer as well. Hopefully I can transition into either C++ or java once I've had my fill of C, as it seems like those two are very widely used. The only issue right now I'm imposed with, is that it feels...
Alright! Thanks alot. I got it to work the way I want it. I use codeblocks as my C compiler and I don't have that issue where it closes too fast. I have to press a key for it to close the prompt.
Just out of curiosity, do you think C is a good program to learn first? I was told otherwise since...
Okay thank you for the help! I used spoiler tags as I thought it was neater, but I'll use code tags instead.
I'm a little embarrassed I didn't even realize the variables were just spelled incorrectly...
The line:
perimter_houseFT =(houseleng perimeter_yardFT, perimter_yardM...
Mod note: Edited the following to remove spoiler tags and to put code in code tags
Homework Statement
Hi, currently I have this assignment:
Write a program by going through the 6 problem solving steps that reads in the length and width of a rectangular yard in feet, the length and width of a...
Yes, it would literally print out √<value of the variance>. I tried the line of code you gave me and it works. Thanks alot!
And yes you're right about the book. I think I'll avoid it for now until I've finished this class(I'm just looking for a variety of books to rely on since it seems...
I apologize for that... I didn't realize the lines weren't identical(you did get all of them except for two though) Thanks for taking the time to read through all of my evaluations.
Line 16 = Line 20
Line 21 = Line 25
I have actually written my own piece of code, and for what its worth it...
Alright so I've dabbled along the internet, I've found code online of what I'm looking for(or close to it) and I've been trying to intrepet it from my end. (Since it seems ill have to improvise considering the due date is on thursday...) Again please excuse my ignorance where necessary. I've...
Thanks a lot for the replies. Good to know that my intuition isn't worthless and I did need to have some background knowledge. Basically my teacher handed this assignment out yesterday, and it is due this thursday. I do not have a class(I do have a lab tomorrow, however I sincerely doubt she...
Homework Statement
Hi, I am currently in a C programming course and i have no background knowledge of programming whatsoever. The professor in my course isn't very good at explaining so I'm a bit lost here. (Please keep in mind, I am NOT asking anyone to do this for me. I would like to know a...