Initializing Array - Equal Sign?

Nov 15, 2014

i know that int [][] x = new int[2][2] will generate a 2x2 array but I'm looking at a certification mock question and I see double [][] da = new double [3][]. What is the empty [] on the right hand side of the equal sign trying to tell me? Is there some default value?

View Replies


ADVERTISEMENT

Byte Array Sign Extend

Apr 27, 2015

I have a checksum function that is suppose to read IPV4 packet and return a short integer value. The IPV4 packets are stored in a byte array. I am having trouble storing the first 8 bits and second 8 bits of the short integer into the byte arrays especially when they have leading 1s. For example, if my checksum returns 5571 (binary = 0001 0101 1100 0011) The first 8 bits is suppose to represent 195 but when I try to assign a larger integer type to a btye the information gets sign extended. The 195 turns into -61. I tried using bit addition like array[10] = array[10] & 0xff, but the result remains the same.

public static short checksum(byte [] a, int length) {
short sum = 0;
long data;
int i = 0;
while(length > 1) {
data = (((a[i] << 8) & 0xff00) | ((a[i + 1]) & 0xff));
sum += data;

[code]....

View Replies View Related

Scanner Array Initializing

Oct 12, 2014

Scanner sc = new Scanner(System.in);
Question question = new Question();
Quiz quiz = new Quiz();
System.out.print("Enter the prompt: ");
question.prompt = sc.nextLine();

[Code] .....

Here is the example run that I am trying to achieve:

* 1. Enter the prompt: What is the capital of the USA?
* 2. Enter a possible answer: New York City, NY
* 2. Is New York City, NY the correct answer (y/n)? n
* 3. Enter a possible answer: Pittsburgh, PA
* 3. Is Pittsburgh, PA the correct answer (y/n)? n
* 4. Enter a possible answer: Washington, DC
* 4. Is Washington, DC the correct answer (y/n)? y
* 5. Enter a possible answer: Chicago, IL
* 5. Is Chicago, IL the correct answer (y/n)? n

The problem is that my for loop runs through correctly the first time, but doesn't seem to react to me initializing my choices array after that. It ends up looking like this:

Enter the prompt: What is the capitol of the USA?
Enter a possible answer: New York City, NY
Is New York City, NY the correct answer (y/n)?n
Enter a possible answer: Is the correct answer (y/n)?

But I cannot understand why it's doing that.

View Replies View Related

C Struct - Initializing 3D Array?

Oct 23, 2014

I have a C struct as follows:

struct myHAI
{
int id;
char celcius[5];
char fahrenheit[5];
 
[Code] .....

I think the Java code is just a little to kludgey. I have to add 256 records to the 3D array which means I have to call the method 256 times. I'd really like to initialize the class all at once similar to the C struct. But I don't know if that is possible. Thus, any less kludgey way of initializing a 3D array?

View Replies View Related

Pass User Input - Initializing Array In Method

Feb 7, 2015

I need to pass user input from the main method, which is then validated using another method that is returned as a valid score, and then I pass the valid input to another method that stores the data in an array. The array is initialized within the method. I tried to use an if-else statement to initialize the array, because I originally did this at the beginning of the method. I soon learned that I was creating a new array everything I accessed the method. Needless to say, this isn't working either.

public static void main(String[] args) {
int judges = 7;
float[] validScores = new float[judges];
for (int i = 0; i < judges; i++) {
float score = -1;

[Code] ....

View Replies View Related

How Many Numbers In Array Have Value Greater Than Or Equal To 100

Sep 10, 2014

I have an assignment that wants me to write a Java function based on induction to determine how many numbers in an array have a value greater than, or equal to, 100.

I have started with:

Java Code:

int recurseHundred (int [] A, int n) {
//n is the number of elements in the array.
//Base case:
if (n == 1 && n >= 100) return A[0];
//Recurse
int num = recurseHundred(A, n-1);
if (n-1 >= 100) return A[n-1];
else return num;
} mh_sh_highlight_all('java');

I don't think this actually does the trick.

View Replies View Related

How To Test For Array Length Equal To Zero

Mar 15, 2015

I am working on an assignment covering exception handling and am stuck on part of the assignment. How can you test for array length = 0?

When I try something like: if (array.length == 0) on a null array, naturally I get a NullPointerException. I would try something like if (array != null) but both array length of 0 and null array are supposed to throw different expressions.

View Replies View Related

Divide Array In Two Parts - Equal To Sum Of Elements

Dec 1, 2014

Divide an Array in two Parts in such a way so that sum will be equal while we add all the elements of array.

View Replies View Related

Comparing Two Array Lists - Output If They Are Equal Or Not

Nov 21, 2014

I need comparing two array lists. For this program i am comparing 2 array lists. The list is integers entered by the user the second is random generated numbers. So far in my program i am able to compare the 2 arrays together and output if they are equal or not however i need the program to output even if atleast one if the integers match,

EXAMPLE list one: 1, 2 ,3 ,4, 5. LIST TWO: 1, 3, 3, 3, 3.

Since the first number matches i want it to out put there is one match, so on and so forth with if there are 3 or 4 matching integers. here is my code so far.

public static void main(String[] args)
{
final int NbrsEntered = 5; //Number of guessed numbers entered
final int LOTTOnbr = 5;
int[] numbers = new int[NbrsEntered];
int[] randomNum = new int[LOTTOnbr];
//int[] TestArrayOne = { 1, 2, 3, 4, 5 };
//int[] TestArrayTwo = { 1, 2, 3, 3, 5 };
boolean arraysEqual = true;
int index = 0;

[Code] ....

View Replies View Related

Array Of Scores - Return True If Each Score Is Equal Or Greater Than One Before

Mar 8, 2014

Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.

scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true

Java Code:

public boolean scoresIncreasing(int[] scores)
{
for (int i = 0; i< scores.length-1; i++) {
if (scores[i] < scores[i+1] || scores[i] == scores [i+1]) {
return true;
} else {
return false;
}
}
return false;
}

Unsure what the problem is, it will always return True for some reason...

View Replies View Related

JRE :: How To Find Certificate Used To Sign App

May 11, 2015

There's a site that uses DBsign UWS to validate personal certificates on a smart card.  I wound up breaking that functionality by moving the default Java truststore so I could create a new one with just root/intermediate CAs that I trust (I have no desire to allow apps signed in China, Russia, Turkey, and countries spelled with heiroglyphs).  Now, my browser believes the UWS is self-signed and rfuses to run it.  I need to find the certificate used to sign that app to see which cert(s) signed it, so I can add them back to the truststore.  How can I find that?

View Replies View Related

Clear Sign Not Working On Calculator?

Jan 15, 2014

Here is the code I wrote:

import javax.swing.*;
import java.awt.MenuBar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NewCalculator implements ActionListener {
//assign button clicked number and answer onto variables.

[Code] .....

Also what is the code I need to use to do the percentage and square root calculation in the calculation. Cos I am not sure about the sign I am required to use to do the calculation.

The if statement is where the code to make the clear button (C and CE) work.

View Replies View Related

Comparing Sign Of A Number In Java?

Sep 23, 2014

I want to check to see if given integers digits a, b are both positive or both negative. How do i do that in java.

how to check below number 'a' is negative or not in if condition using signum method?

if(Integer.signum(a)==-1){

Above line is not working

View Replies View Related

Making Plus Sign To Add Two Numbers In Java

Mar 7, 2015

I am having a bit of trouble making the '+' add two numbers in java. For example:

When the user enters " + 4 5 " I want it to come out as " 4.00e+00 + 5.00e+00 = 9.00e+00 "

Here is what I have so far:
 
public static void main(String[] args) {
 Scanner in = new Scanner(System.in);
 while (in.hasNextDouble()) {
 double num1 = in.nextDouble();
double num2 = in.nextDouble();
String s = "";
 
[Code] .....

View Replies View Related

JSP :: Initializing Captcha From Session

Feb 26, 2015

I am new to JSP and I'm having a problem with captcha containing a value in the field when toggling from the first page to another and clicking submit on the second page before entering data to validate the fields and the code just falls through and returns the error "Please enter the correct code". The values returned are (captcha)96043 (code)null, captcha is not null because it is retrieved from session which is the last value captured from the page I'm assuming.

I've used request.getSession().removeAttribute( "captcha" ); before building the page to clear out the values, resetting captcha to null etc.; nothing is working.

Here's the code:

boolean isPostBack =false;
String captcha = (String) session.getAttribute("captcha");
String code = (String) request.getParameter("j_captcha_response");

[code]....

View Replies View Related

Initializing Variable Within Program

Mar 3, 2014

My objective is to write a program that calculates the bodyfat of people. The difficult thing is, that the calculations are different for males and females, so I tried to prompt the user to state whether they are male or female, then use and "if" statement to tether their response to the corresponding calculations.

Here's my algorithm:

Here's what I have:

package bodyweight;
import java.util.Scanner;
public class Weightcalc {
static Scanner console = new Scanner(System.in);
public static void main(String[] args){

[Code] ....

It keeps telling me that bodyweight is not initialized, but when I do, I get a hell of a lot more bugs on everything telling me they aren't initialized. I just want the program to transfer the user to select inputs, based on whether they are male or female.

View Replies View Related

Initializing Arrays Of Various Types

Sep 18, 2014

For basic arrays, we can directly combine declaration and initialization as E.g: int[] num= new int[2]

But can we do this do for forming class object arrays? like

class stu
{
.....
}
stu[] s=new stu[2]
????

View Replies View Related

Initializing Variables In Two Connected Classes

Nov 3, 2014

I am writing a program with different screens. At first you have to log in to access the program. So I have a problem with the variables username and password. I can't seem to get theme from the DbConnection class. I suppose it is a basic problem?

In the DbConnection class i have a problem with the returns.

In the Login class i have a problem with the connection.getUsername(); and connection.getPassword();

Here is some code:

class DbConnection
package kim.contracts.database;
import java.sql.*;
public class DbConnection {
private Connection conn;
private Statement st;
private ResultSet rs;

[Code] .....

View Replies View Related

Initializing Constructor As Parameter For A Method?

Jan 2, 2014

So, I am learning Swing, and Swing Layouts. I just came across a really confusing (for me) line of code.

Java Code:

setLayout(new BorderLayout()); mh_sh_highlight_all('java');

So, this is weird for me because I don't really understand why the BorderLayout class constructor is being initialized as a parameter for the setLayout..

View Replies View Related

Error Occurs Unless Initializing Variable?

Oct 12, 2014

I don't understand that the error occurs when I don't initialize the variable myPoint. Whereas, I initialize the variable myPoint after variable declaration and before place of error.
 
package enumeration;
import java.util.Random; 
public class Craps {

[Code]....

When I initialize the variable myPoint to zero in its decleration, the error disappear. But why? I have already initialized the variable myPoint in default case before the line of error occured..

View Replies View Related

Initializing Object Outputs Zeroes Instead Of Values Given To It

Oct 30, 2014

public class Check2
{
private int red;
private int green;
private int blue;

public Check2(){
red = 0;
green = 0;
blue = 0;

[Code] .....

And when i uses it in another class named "Check" it returns zeroes :

public class Check
{
public static void main(String[] args) {
Check2 obj = new Check2(125,254,12); // the toString method should return the values i gave it here . but it shows me zeroes instead.
System.out.println("the colors are " + obj.toString());
}
}

Output : the colors are (0,0,0)

View Replies View Related

What Does Setting Object Equal To Another Do

Mar 5, 2014

I've seen this done in code:

For example:

Java Code: BufferedImageOp op = new ConvolveOp() mh_sh_highlight_all('java');

What does this mean? Is it creating an object of convolveOP for the BufferedImage class?

What does it mean when you set an object from one class equal to another?

View Replies View Related

Compare Date Less Than Or Equal To

Feb 20, 2014

How can I compare two date for less than or equal to ?

View Replies View Related

How To Equal Compressed Data

Sep 29, 2014

I have an object that may contain several other objects (sub-object) and will compress those sub-objects.
 
My question is generally what is a good way to compare two objects, as described above, if they are equal (e.g. through equals() function)?
 
Intuitively there are two ways I can think of: 1. Compare each compressed bit

The disadvantage I think is it's not efficient if the object is very big. For instance, when it holds several gigabytes data, it may took too long for just comparing each bit.
 
2. Hash the sub-object before compressing it, and then compare all hashed values. This problem is I am not very sure if hashing is a good way to compare objects. And if collision may be the problem?

View Replies View Related

Equal Values In Two Columns For Every Row In Jtable?

Feb 5, 2014

I have a JScrollPane with two coulmns. In the first column I have an image pane JTable, and in the second a list with names of sections. This second column I try to divide in two columns, one (the second column) to display the names of the sections (each row contains one name), and in the other column (the third) I want to show some values for every section in the row respectively. But, instead of displaying the desired values in the third column, I get the same names of the sections as in the second column. Here is a part of the code I have:

private Vector<Section>daten = new Vector<Section>(0); //These are the values for the first column in the Jscroll
private String[] header = {"Section","calcGYR"}; // These are the values for the second and third column (in this case the header for the both columns
public TrafficObserveModel(Vector<Section> daten) {
setData(daten);

[code]....

But I don't know how to modify the methods in order to render the desired integer values in the third column.

View Replies View Related

Override Equal And Hashcode Method

Jul 7, 2014

I read this tutorial about overriding equal and hashcode method. [URL] ....

I understand how to override equal method, by overriding it, We can custom our compare. I also understand How to override hashcode, To make custom hash.

But still I can not understand why we do it? why if equal method override, we must override hashcode method too?If we don't what is the problem?

To honor the above contract we should always override hashCode() method whenever we override equals() method. If not, what will happen? If we use hashtables in our application, it will not behave as expected. As the hashCode is used in determining the equality of values stored, it will not return the right corresponding value for a key.

Is it the right reason in order to override:

Because when we customize equal method so it focus on special variables,We must change the hash code too in order to match with it, so hashcode also focus on those special variable.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved