WHY AM I NOT GETTING LIKE IN THE EXAMPLES ??!
[1 2 3 4] 0 => [1 2 3 4] am getting this right
[1 2 3 4] 1 => [4 1 2 3] am getting this wrong, am getting [2 3 4 1]
[1 2 3 4] 2 => [3 4 1 2] this is working
[1 2 3 4] 3 => [2 3 4 1] wrong , am getting [4 1 2 3]
[1 2 3 4] 4 => [1 2 3 4] this is working
[1 2 3 4] 5 => [4 1 2 3]
my code should Returns new vector with elements shifted right by a given number of positions.
public Vector shifted(int amount) {
Vector v = new Vector(length);
for (int i = 0; i < length; i++) {
if (i + amount > length-1) {
v.elements[i] = this.elements[(i+amount) % length];
}
else {
v.elements[i] = this.elements[(i+ amount)];
}
}
return v;
}
thanks
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
I am writing a program to play the game "Game of Life". I am hoping someone can help me edit my sad program so that it will print the first board as well as the next generation. The first board is working just fine. It is the next generation that is not working and i'm not sure what I am doing wrong. Thanks in advance. public class Life { public char FirstBoard[][]; public Life() { FirstBoard =...
I spotted a couple of errors, but I am still not getting this code to work. Can someone help? public class Bounds1{ int [][] a1; public Bounds1(){ /* * Create array Dimension 1 */ a1 = new int[(int)(Math.random() * 10) + 1][]; for(int i = 0; i < a1.length; ++i){ /* * Create array Dimensions 2 */ a1[i] = new int[(int)(Math.random() * 20) + 1]; } } public static void main(String[] args){ Bounds1 m = new Bounds1(); for(int i =...
C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null; }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...
I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact { public static void main(String[] args) { Random Rand = new Random(); Scanner sc = new Scanner(System.in); System.out.println("welcome to the contact application"); System.out.println(); int die1; int die2; int Total; String choice = "y";...
I need help with the code below. I am getting an error message I am not sure how to fix import java.util.Scanner; public class DriveTestExams { public static vice main (String[] args);{ Scanner KB = new Scanner (System.in); int IncorrectAns; String[]CA = {"A", "D", "B", "B", "C", "B","A", "B","C", "D","A", "C","D", "B","D", "C","C", "A","D", "A"}; String[]SA = new String [20]; Boolean RightChoice = true; int IncorrectAns = 0; for(int i=o; i <=20; i++){ while (rightchoices); System.out.prinlin ("please enter answer for...
I am using Java to try and solve this problem. Suggestions on
where I am going wrong?
PREVNEXT Workbench ? a Exercise 20662- WORK AREA RESULTS Write the definition of a method named sumArray that has one parameter, an array of ints. The method returns the sum of the elements of the array as an int. x9 of 9: 2018-07-10 12:58:15 -W SUBMIT 1 public int sumArray(int[] a) 2 int i; int sum = 0; for (í 0; í?a.length; ?++)...
I am currently using eclipse to write in java.
A snapshot of the output would be greatly appreciated to verify
that the program is indeed working. Thanks in advance for both your
time and effort.
Here is the previous exercise code:
/////////////////////////////////////////////////////Main
/*******************************************
* Week 5 lab - exercise 1 and exercise 2: *
* ArrayList class with search algorithms *
********************************************/
import java.util.*;
/**
* Class to test sequential search, sorted search, and binary search
algorithms
* implemented in...
I have spent so much time on this and I am having trouble getting all the methods to work together correctly to run the code right, and I am not sure what is wrong with it. /* You will recreate one or two versions of the logic game shown in the Algorithms movie and you will ask which one the user would like to play. Upon completion of the game, display who won and ask if they would like to...
I am getting an error in R and am unsure how to correct it. I am
getting an error from the r2 line, "Error in xc[1:(n - 2)] : only
0's may be mixed with negative subscripts."
tmpFn <- function(xVec)
{
xc <- xVec - mean(xVec)
denom <- sum(xc^2)
n <- length(x)
r1 <- sum( xc[2:n] * xc[1:(n-1)] )/denom
r2 <- sum( xc[3:n] * xc[1:(n-2)] )/denom
list(r1 = r1, r2 = r2)
}
tmpFn(seq(2, 56, 3))
10. (a) Given a...
Two questions, 1) how do I do this, 2) what is wrong with my
code
norm krumpe@muohio.edu program11 even Positions prev I next chance Given an array of integer values, return a new array consisting only of the elements that have even- numbered indexes. even Positions([7, 51) [7] even Positions([8, 1, 7, 4, 6, 10, 5]) [8, 7, 6, 51 evenPositions([13]) [13] Save, Compile, Run Go int[1 even Positions(int[] nums) int[] newArrays new int[nums. length/2]; for (int i 0; iknums.length;...