Create Array That Produces Triangular Number Sequence?
Nov 12, 2014
My code complies but it won't run and I'm not sure why. ArrayIndexOutOfBoundsException.
I'm trying to create an array that produces the Triangular number sequence:1, 3, 6, 10, 15, 21, 28, 36, 45, ...
Attached image(s)
View Replies
ADVERTISEMENT
Mar 24, 2015
I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.
I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.
The list consists of the following wifi related values:
MAC-Adress, SSID, Timestamp, Signalstrength.
These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.
The catch is, we are not allowed to use any of the following:
java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.
So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.
Below is my Code (Its still an active construction zone):
public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];
[Code] ....
View Replies
View Related
Sep 17, 2014
I want to declare integers, while the program is running.
I run the program and then I give it via System.in.println an integer and repeat this as long as I want. I want the program to give those integers a name of a certain type for, for example a(i) or a[i], dunno, (it should be handy) and then a(i) represents the the i'th integer I gave the program. My idea is then that I can use those elements by their name just like, if I had declared them in the first place. For example add two integers together. For example I defined a method add+, which waits for 2 integer and then adds them. For example I write:
add
a(2)
a(47)
(then I would get here the result.)
However I don't know, how to let the program count the number of inputs or how to let it declare and use variables.
View Replies
View Related
Sep 17, 2014
I want to declare integers, while the program is running.
I run the program and then I give it via System.in.println an integer and repeat this as long as I want. I want the program to give those integers a name of a certain type for, for example a(i) or a[i], dunno, (it should be handy) and then a(i) represents the the i'th integer I gave the program. My idea is then that I can use those elements by their name just like, if I had declared them in the first place. For example add two integers together. For example I defined a method add+, which waits for 2 integer and then adds them. For example I write:
add
a(2)
a(47)
(then I would get here the result.)
I don't think implementing the add function is difficult. However I don't know, how to let the program count the number of inputs or how to let it declare and use variables.
View Replies
View Related
Feb 21, 2014
how to create dynamic string array if we dont know number of strings in the beginning?
View Replies
View Related
Oct 30, 2014
I have to find where in the fibonacci sequence a at number belongs, using a if or while loop.
Example
>55 is a Fibonacci number whose order in the sequence is 11
>35 is not a Fibonacci number. However, it lies between Fibonacci numbers 34 (order: 10) and 55 (order: 11)
import java.util.Scanner;
public class While {
public static void main(String[] args) {
System.out.println("Welcome to the Fibonacci Sequence Detector");
Scanner in = new Scanner(System.in);
[Code] .....
View Replies
View Related
Apr 29, 2014
Write a recursive method that calculates the Nth number in the Fibonacci sequence. The first and second numbers in the sequence (the base cases) are both 1. After that, each subsequent number is the sum of the previous two. Stated a bit more formally:
fib(n)={1fib(n−1)+fib(n−2)n<2otherwise
For example, here is the first few numbers in the sequence:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Your fib method should be part of a class named Fibonacci. In addition to the fib method, the Fibonacci class should have a main method that calls fib(9). If the result doesn't equal 34, you should print an error message. Otherwise, it should print out a message saying that it was successful.
After writing your Fibonacci class, answer the following question: How many times is the fibonacci method called when calculating the 5th number in the sequence?
View Replies
View Related
Mar 3, 2015
I am trying to create a basic graphical user interface for sequence translation (including a JTextField for the description of a sequence and status of function button pressed e.g. “simple” translation and input and output TextFields). This involves a number of different class files. I cannot get my user interface to do what I want and I think I have problems with my "actionPerformed" method. How the code should be linked together?
public void actionPerformed(ActionEvent event) {
try {
// Get the description, content and result
String d = tool.getDescription();
String input = tool.getInputText();
Stringr = translation.getResult();
[code]....
View Replies
View Related
Oct 26, 2014
From a given array of positive and negative numbers, I have to find the longest SUB-Array which represents a Zig-Zag sequence...
A Zig-Zag sequence means that one number is possitive, the next one negative, the next one possitive, and so on and so on...
Like this: -1, 4, -5, 6, -9, 2, -9 etc....
So that means, if the array looks like this:
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
the longest sub-array which fulfills the requirement is (the part in bold):
1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3
and I only need it's length, which in this case is: 8
View Replies
View Related
Mar 11, 2015
I have a simple WORKING Factorial program code but I don't understand how it works.Here is code snippet
public class Factorial{
public static void main(String[] args){
long limit = 5;
//long factorial = 1;
[code]....
My question is - every time in a given FOR loop if Factorial value (highlighted and bold above) is initialized / reset to "long factorial = 1" then how does code produces correct values? Because correct values can be produced only if interim factorial results are saved/stored and used next time to multiply with "factor" value.
Here instead of retaining it, we initialize or reset to 1 so every time you multiply by 1 and it should produce 1! = 1, 2! = 2, 3! = 3, 4! = 4 etc which would be an incorrect result.
View Replies
View Related
Mar 12, 2014
Modify the Improved Fibonacci application to store its sequence in an array. Do this by creating a new class to hold both the value and a boolean value that says whether the value is even, and then having an array of object references to objects of that class.
Did I just need to declaring the variable in other class (for boolean value and the value itself) or else ?
Here is the code for ImprovedFibonacci.java
Java Code:
class ImprovedFibonacci {
static final int MAX_INDEX = 9;
/**
* Print out the first few Fibonacci numbers,
* marking evens with a '*'
*/
public static void main(String[] args) {
int lo = 1;
int hi = 1;
String mark;
[Code] ....
View Replies
View Related
Feb 28, 2014
Design and implement an application that produces a multiplication table, showing the results of multiplying the integers 1 through 12 by themselves
View Replies
View Related
May 18, 2015
I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.
View Replies
View Related
Dec 5, 2014
java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.
View Replies
View Related
Aug 3, 2014
I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9
6 1 2
5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*;
public class Spiral
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int n=Integer.parseInt(br.readLine());
[Code] .....
View Replies
View Related
Oct 13, 2014
so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else
import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
[code]....
View Replies
View Related
Jan 15, 2014
just started programming in Java. My goal in this part of code was to read out the first array, while saving the number of the chart in the array to a new array.
first question: is the code clean and the method correct?
2nd question: i get an error when i try to print the newInt Array for no apparent reason.
Java Code:
public class viereinsdiezweite {
public static void main(String[] args){
int[] newInt = new int[20];
int specialInt = 3;
int[] bigInt = new int[]
[code]....
View Replies
View Related
Apr 12, 2015
I have a requirement like to attach most suitable flow to a request
Flows should be like below (eg:Flow1) .We can create n number of flows with any combination of values.
When I tried to create a request that have all the features in the flow. And I have to attach the most suited flow to that request.
Suppose my request have the feature Place = Place1 and company =Comp1 and Job=Job1 .here most suitable flow is Flow1.
So my question is how can I implement the logic in java for getting the most suitable match.
View Replies
View Related
Mar 30, 2015
I am writing a program which writes down all possible equation y=a+b+c values from min to max (in reality this equation would more difficult, but here is just short example).
The problem is that my sorting code can't get access to full array in loop.
Is there any way to pass array to sorting code, or somehow change sorting code?
package pkg06;
public class Main {
public static void main(String[] args) {
double aS =-1;
double aE = 3;
[code]...
View Replies
View Related
Mar 4, 2014
I need to create a method that returns a new array containing the componentwise sum of its arguments(if length is the same). For instance, if the input arrays are {0,1, 2} and {2, 2, 3} then the output is {0+2, 1+2, 2+3}, i.e. {2,3,5}.If the input arrays have different numbers of elements, the method should return null.
I came with something like this, however i dont know how to make a copy of an array from two arrays. My code obviously wont compile. package whatever;
import java.util.Arrays;
public class hhhh {
public static void main(String[] args) {
double [] a = {1,2,3};
double [] b = {2,3,4};
[code]...
View Replies
View Related
Jan 27, 2014
You are given an array A with elements 0 to n-1, numbers can be repeated in the array. Create n sets where
S[i]={a[i],a[a[i]],a[a[a[i]]]...}.
Set has all elements unique. Find the size of the largest set.
Input:
First line contains n, size of the array. n<1000
Next lines contains n numbers, each element of the array
Output :
Prints one number: Size of the largest set.
Sample Test Case:
Input: {3,1,2,0}
Output: 2
Explanation:
Four possible sets are
{3,0},{1},{2}{0,3}
View Replies
View Related
Dec 15, 2014
Create a java application that contains an array of 10 multiple-choice questions related to you favorite hobby. each question contains three answer choices. also create a parallel array that holds the correct answer to each question - A,B, or C. display each question and verify that the users enters only A,B, or C as the answere - if not, keep prompting the user until a valid response in entered. If the user responds to a question correctly, display "Correct!"; otherwise, display the correct answer is and the letter to the correct answer. After the user answer all the question, display the number of correct and incorrect answers.
View Replies
View Related
Mar 2, 2015
In my programming class we need to create a large test array of Longs to iteratively sum/reverse the array and recursively sum/reverse the array.creating the array and where to go from there.
View Replies
View Related
Dec 17, 2014
I am trying to create two arrays containing JLabels i am really stuck here and i am unable to move on .
[code]
public class display extends javax.swing.JFrame implements Runnable {
/**
* Creates new form display
*/
String[] images = {"1", "2", "3", "4", "5", "6"};
JLabel[] lblArrayComp = {displayC1, displayC2, displayC3, displayC4, displayC5};
JLabel[] lblArrayPalyer = {displayP1, displayP2, displayP3, displayP4, displayP5};
display player = new display();
display computer = new display();
[Code] ....
View Replies
View Related
Mar 3, 2014
i need to create a program that asks the user for an array and then asks the user to fill in the slots of the array but i have to do it in a method
View Replies
View Related
Jan 2, 2014
Im looking for a means to store groups of static data..
so I understand these simple string arrays...
Java Code:
private static String[] names = new String[] {
"aidanmack",
"johnsmith"
}
private static String[] ages = new String[] {
"30",
"30"
} mh_sh_highlight_all('java');
But can I not combine that into an array of objects? something along the lines of what you would do with json? like...
Java Code:
private static array[] multi = new array(){
{"name":"AIDANMACK","age":"30"},
{"name":"johnsmith","age":"31"}
} mh_sh_highlight_all('java');
View Replies
View Related