I just recently started coding java and i have a problem.... So I was doing an exercise on LearnJavaOnline. The exercise was: Create all the the primitives with different values. Concatenate them into a string and print it to the screen so it will print: H3110 w0r1d 2.0 true.I attempted it and this is what i wrote
public static void main(String[] args) {
char H = 'h';
byte e = 3;
short l = 1;
int L = 1;
long o = 0;
char w = 'w';
[code]....
However it prints "109 w0r1d 2.0 true".But when i add 2 speech marks: String HelloWorld = H+""+e+l+L+o+" "+w+0+r+one+d+" "+two+" "+hi; It works perfectly.
Take a Java (Oracle SE 7 JVM) long, primitive or it's wrapper class... assign a variable with the value slightly less than 2^63-1 (the maximum value... i.e. infinity? for a long); keep adding 1. What happens? You quite quickly get - minimum long, or minus infinity (?).Infinity is my perspective from a Mathematics degree.
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12; int i = 1; int k = 0; int[] factors = {} while (i<x) { if (x%i==0) { factors[k] = i; k++; i++;
Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.
No input prompt Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems) Use hasNextInt() to terminate your input Format as below (slightly different from the text example) Z:dbraffittWeek10> javac Histogram.java Z:dbraffittWeek10> java Histogram
[Code] ....
What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.
import java.util.Scanner; public class Histogram { public static void main (String[] args) { Scanner scan = new Scanner (System.in); int [] nums = new int[101];
Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?
import java.util.Scanner; public class ArrayExamples{ public static void main(String[] args) { Scanner input = new Scanner(System.in); double exampleArray[] = new double[5]; System.out.print("Enter a Number: "); int num1 = input.nextInt();
I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:
currentBuffer= BufferTools.reserveByteData(mapSize); glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer); for (int i = 0; i < mapSize; i++) { if (currentBuffer.get(i) != baseBuffer.get(i)) { //Do nothing continue; } //Do something }
This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene".
I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.
My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.
Because at their I will use something request.getAttribute("Attr_Name");
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.
In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.
package com.scg.athrowaway; import java.util.Calendar; import java.util.Date; public class DateRange { private Date startDate; private Date endDate;
I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.
Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
I'm doing an aggregation exercise that's suppose to find the volume and surface area of a cylinder. What I'm trying to do is pass values from one class, to a second class, and that second class passes values to a third class.
This may be a clearer explanation: The first class is the main program which sends values to the second and third class. The second class is used do calculations for a circle (a pre-existing class from another assignment). The third class grabs the values that the second class calculated and calculates those values with the one that was passed from the first class to the third class. The first class then prints the outcome.
Problem is when the program gets to the third class, it just calculates the value from the first class with the default constructor from the second class. It's like the second class never received the values from the first class. I think I'm missing a step, but I don't what it is.
First Class:
package circle; import java.util.Scanner; public class CylinderInput { static Scanner in = new Scanner(System.in); public static void main(String[] args) { //user defined variable
I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:
Java Code: public class Sphere { // instance variable (i.e., a field) private double radius; // constructor for the Sphere class public Sphere(double r) { radius = r;
public static void main() { int i; // counter createDeck(); // this is a function call // Show the cards in the deck System.out.println("The deck is as follows:"); for (i=0 ; i < CARDS_IN_DECK ; i++)
[code]....
It is now printing out the value of myDeck[5] but I need to print out first 5 values.
how can i get id from db table for each column values with java or oracle query? i did get before each column content from file and now i need get the id of this column values from db. I read csv files from folder and then load the data from these files into subfolder, and here with line li = line.split(","); i get the values that i have in csv file and split them and become in li the value name, and then in else block i create a P objekt where i set this values from csv files, and with [I]p.setLid(li);
I set the value for all valuenames, and then get these valuenames in separate column with other content from this csv, and my question is, i need to do this with db, and write these csv file values to the table in db (it will be done with another java class), what i need, that to write the ids of these values into the table in db, instead of valuename, and while there is no ids for valuenames in csv files, i need to get the id from the table in db where these are already listed with sequences.
I don't know how can i write in data table the id of this valuenames and other content, this data table should contain the ids of valuenames timestamp values and the ids of the csv files name, i don't know how to do this with the ids, i must get the ids from the db table and then set these on [I]p.setLid(li); where i set early the valuenames, instead of valuenames i should set ids, that will set ids automatically for all these valuenames.
try { while ((line = br.readLine()) != null) { if (lc == 0) { li = line.split(","); } else { String[] temp = line.split(","); for (int i = 1; i < temp.length; i++) { p = new P();
[code]....
i got the values that then will be given to [I]p.setLid(li); and iterate, but now i want to get id from the table in db where this values stored with id instead of this column values, how can i do it?
My initial question had to do with looping but now I'm having trouble adding certain variables.
The original thread is here: [URL] ....
If you look at the end of the code it won't recognize the "overtime" and "hourDiff". I have to use it for each level the user chooses and am not sure how to do so. Even if I put it under the if{ statement it won't calculate. I assume it's due to it being cut off from other blocks but I'm not sure how to combine them.
My code is:
import javax.swing.JOptionPane; public class Pay { public static void main(String[] args) { double salary2 = 20.00; double salary3 = 22.00;
public void actionPerformed(ActionEvent ae){ float A=0; int a = Integer.parseInt(tf1.getText()); if(ae.getSource()==b2) { A=(((30*a*14) / 100)+(30*a));
This simple program should build a new table with random values and on the getValue method (perhaps called from othe TestClass) return back content of particular cell. why my getValue method doesn't work. Nay! It returns error while compilation.
import java.util.Random; class TablicaIntowa{ public int getValue(int a){ return tabl[a]; } //getValue method end
I have created a class and a matrix of doubles (or at least, I think I have, that's partly what I want to verify).I need to return the values of the array,Here is my class:
public class example{ double[][] Position=new double[2][11]; double calculate(){ for (int time=0;time<=10;time=time+1){ Position[1][time]=time; Position[2][time]=time+1; double A=Position[2][time]; return A; } } }
I am getting the error: "This method must return a result of type double", though to me it looks like I am returning double (A).
I am trying out jsp and servlets now for the first time. I have to insert two data, car code and car name into a mysql table. I got those details using jsp but if I use form, it redirects to another page for insertion. I want the data to be inserted and still remain in same jsp page. I am thinking of using onClick from javascript but as I googled this many places have said it is a bad idea to use jsp inside javascript. If so how can we insert data to mysql table without redirecting to another page?
I am storing out of range values in int and byte type
public class OverflowDemo { public static void main(String args[]) { int value = 2147483647 + 10; System.out.println(value); byte b=127+10; System.out.println(b); } }
Program will give error for only byte type as OverflowDemo.java:8: error: possible loss of precision
when i input a positive integer it works but when i input a negative number it doesn't work
my pseudo code:
READ input WHILE( NOT CORRECT INPUT) READ INPUT AGAIN; ENDWHILE DECLARE array arr[input] FOR(i=0 to input-1) arr[i]= Random number from 0 to 100; ENDFOR DISPLAY ARRAY
error message when i input -5 : Exception in thread "main" java.lang.NegativeArraySizeException atPosNeg.main<PosNeg.java:36>
import java.util.*; class PosNeg{ public static void main(String args[]) { Random generator = new Random(); Scanner scan = new Scanner(System.in);
Is there any alternative on executing request.getParameter on the id's of input text in order to set it on the Transaction bean so that the values will display on the user when the page reloads?