Error Adding Two Numbers?

Nov 5, 2014

package calculator;
public class operations {
int a = 5;
int b = 10;
public void add(int a,int b)
{
int c = a+b;
System.out.println(c);
}
}

I am not getting output to this question though it runs.

View Replies


ADVERTISEMENT

Adding Numbers In Table?

Mar 11, 2014

how can I add the numbers in quantity where it will automatically put in total?

im using netbeans.

just want the codes for how to add the listed quantity?

View Replies View Related

Java Calculator - Numbers Are Not Adding

Jul 12, 2014

So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

Adding And Subtracting Positive Or Negative Two Numbers Of Any Length With Strings?

Feb 3, 2014

You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number. And, the operations must be done by adding or subtracting characters directly. You are not allowed to convert these strings to numbers before the operation.

The program must use a "Number" class which includes at least the following methods:

Number ( );
Number (double n);
Number add (Number RHS);
Number subtract (Number RHS);
String toString ( );

This is what i have but it only adds positive numbers and it doesn't subtract problems like 7.05-8.96. Also some of it was what our teacher gave us like alignwhole method

import java.util.Scanner; 
public class Number{
private String whole;
private String decimal;
private String sign;
  public static void main (String[] args){
 System.out.println("Enter two numbers");

[code]....

View Replies View Related

Adding And Subtracting Positive Or Negative Two Numbers Of Any Length With Strings

Feb 5, 2014

You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number. And, the operations must be done by adding or subtracting characters directly. You are not allowed to convert these strings to numbers before the operation.

The program must use a "Number" class which includes at least the following methods:

Number ( );
Number (double n);
Number add (Number RHS);
Number subtract (Number RHS);
String toString ( );

The below code is what our teacher gave us to start with, but it needs to add and subtract positive or negative numbers of any length. This code only adds positive numbers. Need to write code for subtraction .

Java Code:

import java.util.Scanner;
public class Number{
private String whole;
private String decimal;
private String sign;

[Code] .....

View Replies View Related

Adding Fractions - Loop For Calculating Total Of Series Of Numbers

Mar 8, 2014

I'm just not noticing why it won't display the answer. I'm trying to solve this book problem......

"Write a for loop that calculates the total of the follower series of numbers:

1/30 + 2/29 + 3/28......+30/1"

Here is what I have..

public static void main(String[] args) {
double total = 0;
for (double a = 1, b = 30; b < 1; a++, b--) {
total += (a / b);
}
System.out.println(total);
}
}

When launched, the output is 0.0. I tried changing the variables a and b to doubles but didn't change anything...

View Replies View Related

Error When Adding Images?

Jan 16, 2014

I have been trying my hand at making 2d top down view games and have found myself repeatedly using the same code so i created a file with all the functions so when it is down i just import the jar and dont have to keep rewriting functions. I have trouble because the background is loaded on the screen and i dont know why as i didn't tell it to load. In fact I set the panels visiblity to false. Both of my classes are in the same package. Why I still get the Image.

Walking Turtle
Java Code: import javax.swing.*;
import java.awt.event.*;
public class turtleWalker extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame("Walking Turtle");

[code]....

View Replies View Related

Error In Adding In ArrayList

Apr 19, 2014

package eg.edu.guc.iphone.tiles;
import java.util.ArrayList;
import eg.edu.guc.iphone.Location;
public class Square extends Piece {
private ArrayList<Location>possibleMoves;

[Code] ......

View Replies View Related

Lottery Game Matching Numbers Error

Dec 11, 2014

import java.util.Scanner;
import java.util.Arrays;
public class LotteryTester {
public static void main(String[] args) { 
LotteryApplication lottery = new LotteryApplication();
int lotteryNumbersCount = lottery.getLotteryNumbers().length;
 
 [Code] ....

Everything works fine but when I run it the matching numbers tends to be off. For example I will type Enter in 1,1,1,1,1 for my 5 numbers. The lottery numbers will be 5,3,4,5,8 and it will say 1 number matched.

View Replies View Related

Method To Format Telephone Numbers - String Index Out Of Range Error

Jan 25, 2015

I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.

public static void main(String[] args) {
int intBegin = 0;
int intEnd = 1;
int length;
String charact;
StringBuilder numbuilder = new StringBuilder();

[Code] .....

The error message I'm getting is:

run:
The length is 13
intBegin is at 0
intEnd is at 1
index is at 0
Charcter ( was not inserted

[Code] ....

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000

public class primenumber {
public static void main(String[] args) {
long start = 5000000;
long end = 10000000;
System.out.println("List of prime numbers between " + start + " and " + end);
for (long i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.println(i);

[Code] ....

View Replies View Related

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.

[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);

[Code] .....

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m

y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.

public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];

[Code] ....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Generate Two Arrays - One With All Positive Numbers And Another With Negative Numbers

Mar 10, 2015

Create an integer array with 10 numbers, initialize the array to make sure there are both positive and negative integers. Write a program to generate two arrays out of the original array, one array with all positive numbers and another one with all negative numbers. Print out the number of elements and the detailed elements in each array.

public class problem3 {
public static void main(String[]args){
int[] numbers = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5};
for (int i = 0; i<numbers.length;){
if(i>0){
System.out.println(numbers);
}
else
System.out.println(numbers);
}
}
}

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

JSP :: Eclipse Project Window Shows Error But Code Editor Shows No Error

May 22, 2014

For my jsp file, the code editor shows no error, but the projects window shows an error. I built my project again, cleaned the project, restart eclipse twice and summoned cthulhu. But my project still shows an error. How do I find the cause.

Eclipse project -

JSP file -

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="mine" uri="DiceFunctions"%>

[Code] ....

View Replies View Related

JSP :: Error Page Is Not Displaying Instead Error Status Code Is Displaying

Apr 5, 2014

I have written some error checking code

File name ErrorPage.jsp

<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error</title>
</head>

[code]...

I have put error.jsp and badpage.jsp file in public access folder that is web content in eclipsewhen I am running the code I am status code of 500 and not the errorpage.jsp message .

View Replies View Related

Array Not Adding 1?

Jan 1, 2015

I am working on a text based adventure game. (This is NOT OOP at all) The problem comes in at my second if statement inside my loop, it is not adding 1 to my array locations[] it keep printing location[0] then a 1 at the end. Not really sure what is going on here. I would like it to when I type "Go north" it adds 1 to locations[]

E.G
locations[0]
Go north
locations[1]
go north
locations[2]
package com.PenguinGaming;
import java.util.Scanner;
public class Game{

[code]....

View Replies View Related

Adding JLabels To GUI

Apr 5, 2014

I'm really struggling adding JLabels to my GUI. The code is giving no errors but the JLables aren't showing up as I think I've done something else wrong. Here's my method for adding the JLabels:

public void showGraphics(){
for(int i=0; i<message.length(); i++){
if(message.charAt(i) == '#'){
JLabel localLabel = new JLabel("test label");
getContentPane().add(localLabel);
}
}
}

I think the problem might be to do with how the rest of the GUI is setup and the fact that I haven't specified where to add the JLabel just that I'm adding them.

Here's what my GUI looks like.

I want the JLabels above the JTextArea.

View Replies View Related

Adding Image To GUI

Jul 28, 2014

Code of file:

Java Code: import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

[code]...

The serializable class ImagePanel does not declare a static final serialVersionUID field of type long public class ImagePanel extends JPanel{ ^^^^^^^ ^ ^^2 problems (1 error, 1 warning) mh_sh_highlight_all('java');

im basically just trying to put the image inside the GUI and centre the text underneath it. Which is hard to believe since the text is above the image in the code .

View Replies View Related

Adding Bill / Tax And Tip

Feb 1, 2014

I'm trying to make a simple program that will show the amount of a bill, the tip, tax and total with all 3 added.

Right now i am having issues with line 12. I am getting the error "Variable amount might not have been initialized

I thought i did initialized it.

import javax.swing.JOptionPane;
public class BillAmt {
public static void main(String[] arg) {
String amt;
double tax, taxTotal, tip, total;
tax = 6.75;
double amount;
taxTotal = amount + tax;
tip = taxTotal *.15;
total = tip + taxTotal;
amt = JOptionPane.showInputDialog("Please enter the amount: ");
amount = Double.parseDouble(amt);

View Replies View Related

Adding Values Within Jtextfield?

Mar 25, 2015

I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class

public class Product {
private String name;
private double weight;
private double price;

[Code] ....

with getters and setters excluded, and the list these are put into

public class productList extends DefaultListModel {
public productList (){
super();
}
public void addProduct (String name, double weight, double price, int code){
super.addElement(new Product(name, weight, price, code));

i have the price for each product to be displayed in a text field with the following code

addBasketItem = new JButton();
getContentPane().add(addBasketItem);
addBasketItem.setText("Add >");

[Code] ....

defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.

This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.

View Replies View Related

Adding Validation To A Constructor?

Nov 17, 2014

I want to add validation to some of the elements in my constructor.

Person(String idIn, String nameIn, ) {
this.id = idIn;
this.name = nameIn;
}

I want to be able to check that the data for the ID is limited to a certain collection of characters formatted in a certain. For example, I may wish to limit it to 5 lowercase letters or numbers, or a combination of both. How could I do this?

View Replies View Related

Adding Outputs From For Loop

Apr 12, 2015

Here is my program. I have to add the outputs from variable 'done' together. It seems to not work inside or outside the loop.

//A program that will find the last/check digit of a Book ISBN number.

import java.util.*;
public class ISBN {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter the ISBN number>");
String isbn = kb.nextLine(); //Even though the ISBN code is a number,

[Code] .....

View Replies View Related







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