Add / Subtract / Multiply And Divide To Get Irrational Number

May 12, 2014

public static void main (String [] args) {
int a = (int) 0.25;
int b = (int) 1.25;
int result = a + b;
System.out.println("Result of addition is "+ result);
}
}

View Replies


ADVERTISEMENT

Multiply Every Number In Array By 2 And Print It Out

Nov 2, 2014

My assignment is to write some code that will multiply every number in an array by 2 and print it out. This is using a site zyante which is a interactive online book kind of thing.

I have tried For (i=0; I < 8; i++) with like userVals = userVals * 2) }

And it doesn't like that so i'm guessing i am no where close to right. The chapter doesn't give me any example of doing anything close to this so i am completely lost on what i have to do.

This is the program :

import java.util.Scanner;
 public class NegativeToZero {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_ELEMENTS = 8; // Number of elements

[Code] .....

View Replies View Related

Multiply Two Numbers - Add X Number Y Amount Of Times

Jun 9, 2014

I am trying to make a program to multiplies two numbers without using the "*" operator. My idea was to add x number y amount of times, which is the same as multiplication. I did this with a for loop, but zero is always returned as the answer. How can I fix this?

public class secondMult {
public static void main(String[] args){
System.out.println(multWithSum(4,5));
}
public static int multWithSum(int x, int y){
int sum = 0;
for(int i = 0; i==y;i++){
sum = sum + x;
}
return sum;
}
}

View Replies View Related

Why Substring Method Subtract Extra 1

Sep 10, 2014

Why does the substring method subtract an extra 1?

For example:

myString = "Programming and Problem Solving";

myString.substring(0, 7) would be "Program" instead of "Program".

It's not explained in the book I'm reading and didn't see it online.

View Replies View Related

Subtract One User Inputted Integer From Another - Bad Operand Types

Mar 6, 2014

I've been working on this problem for a while now and continue to get an error when I try to subtract one user inputted integer from another. It seems to compile fine for adding, dividing, and multiplying. Why it might be making that error and how to resolve it? (As an aside, I have no idea if I did the whole program right but am just trying to figure out why a declared int would come back with an error it's a string.)

import java.util.Scanner;
public class Calculate2
{
public static void main(String[] args)
{
int firstInt;
int secondInt;
int choice;

[Code] ....

View Replies View Related

Method To Add And Multiply Integers

Mar 12, 2015

Develop a method that accepts as data input three integer numbers, calculates the sum and the product of the numbers, and displays the sum and product.

View Replies View Related

Value Will Multiply By User Input

Apr 14, 2014

I would like to multiply the amount stated inside program by user input. I currently have

public static void setTicket(double ticket)
{
//if statement for tickets
if (ticket == 1)
Ticket = 10.00;
else if (ticket == 2)
Ticket = 20.00;
else if ( ticket == 3)
Ticket = 30.00;

The user should enter 2 and the value should show 20.00. This does work however im looking for a way to say enter 2 = 2*10 instead of stating each value individually.

View Replies View Related

Not Getting Divide By Zero Error

Dec 31, 2014

here is code :

public final static void main(String[] args){
double d = 10.0 / -0;
if(d == Double.POSITIVE_INFINITY)
System.out.println("Positive infinity");
else
System.out.println("Negative infinity");
}

now ideally this might throw Arithmetic Exception.. but it prints positive infinity ,.. why.. ??

View Replies View Related

Divide And Conquer

Oct 28, 2014

I believe i need Divide and Conquer method, maybe im wong..

I have to solve this:
x2+s(x)+200·x=N

N is given by the user, also A and B, which is the range of X.
but the range can be up to 1,000,000,000

View Replies View Related

How To Divide More Than Two Numbers Using ArrayList

Jun 11, 2014

I made a calculator that does the basic operations but I want to be able to divide more than two numbers by repeatedly entering values using an arraylist and I keep getting the indexoutofboundsexception and I don't know why? I understand the reason behind the outofboundsexception but I can't figure out why in this case. Here is a snippet:

public Double division(ArrayList<Double> list){
Double dnum = 0.0;
Double divide = numList.get(0); // Initialize divide to first element in the arraylist
for(int i=0; i < numList.size(); i++){

[Code] ....

View Replies View Related

Divide And Conquer Algorithm Implementation

Oct 18, 2014

I was given an algorithm to implement and i did it in java. its some divide and conquer algorithm probably some comparison sort..heres the code i wrote...

import java.util.*;//so as to get the functions for using arrays
public class main
{
public static void main(String[] args)
{
int m[]={10,2,3,4,5,6,7,8,9,1};
int result[]=new int[200];

[Code] ....

the program compiles without errors. but while running i get the following errors:

java.lang.ArrayIndexOutOfBoundsException: 10
at main.abc(main.java:28)
at main.main(main.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

View Replies View Related

Calculating Area Of A Rectangle (height Multiply By Width)

Mar 19, 2014

I was suppose to create a simple Java program for calculating the area of a rectangle (height * width). Then check the user’s input, and make sure that they enter in a positive integer, and letting them try again if they enter in a negative number. (I'm not sure how to get them to try again.

I am suppose to use an "if" statements and indeterminate loops to achieve the solution. The program will have the following requirements:

1. Ask the user to enter in both a height and width (as an integer)
2. If the user enters in a negative number, display an error
3. If the user enters in a negative number, give them another chance to enter in the correct value
4. Calculate the area and display to the screen once two positive integers have been entered.

import java.util.Scanner;
public class RectangleAreaCalc
{
public static void main(String[] args)
{
int length;
int width;
int area;
 
[Code] ....

View Replies View Related

User Input In Miles And It Is Supposed To Multiply With Feet

Sep 21, 2014

I have a program where the user enters in the miles and then it is supposed to get multiplied by feet but I keep getting this error.

GetUserInfo.java:12: error: bad operand types for binary operator '*'
int total = name * feet;
^
first type: String
second type: int

1 error

This is my code so far :

import java.util.Scanner;
public class GetUserInfo
{
public static void main(String[] args) {
String name;
int miles;

[Code] ....

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

I/O / Streams :: Divide A Text File Into Blocks Of 128 Bits

Feb 7, 2006

I have to divide a text file into blocks of 128 bits. I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail. or it would be much better if you could show me a portion of the code.

View Replies View Related

Swing/AWT/SWT :: Java2D Graph Plotting - Divide X And Y Axis With Frequencies

May 29, 2014

I am using Java 2D API to implement Graph plotting. I am able to transform and scale the origin upright.

Now, I need to divide the x & y axes with frequencies (Ex: On Y-axis: 0 10 20 30 40 etc ..) and then plot points (Ex: [34, 54] etc) accordingly.

Which methods to use or way out to make this implementation?

View Replies View Related

Number Guessing Program - Computer Guesses A Number That User Is Thinking Of Within Certain Range

Mar 28, 2015

I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.

-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:

Welcome to this first-ever mind-guessing program!

Please pick a range (higher than 1 and no larger than 50): 32

You will choose a number between 1 and 32... and I will try to guess it.

With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.

-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:

My fourth guess is 17: h
My guess is too high?

My fifth guess is 16: h
*** I am unlucky this round. I give up.

Let's play!

My first guess is 10:
etc..

import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;

[Code] ....

View Replies View Related

User Enter 5 Digit Number And In Return List Each Number On Their Respective Lines

Sep 16, 2014

So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.

View Replies View Related

Program That Takes A User Inputted Number And Converts It To A Binary Number

May 5, 2014

trying to write a program that takes a user inputted number and converts it to a binary number.

Here's what I have:

package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();

[Code]...

Bugs on:

Line 13
Line 17
Line 23

View Replies View Related

Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies View Related

Compute Recursively Total Number Of Blocks In Triangle With Given Number Of Rows

Jul 8, 2014

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

triangle(0) → 0

triangle(1) → 1

triangle(2) → 3

View Replies View Related

Creating Method That Prints The Square Root Of A Number Up To A Certain Number?

Feb 27, 2015

I am trying to create a method that prints the square root of a number up to a certain number. It needs to take a single int parameter for example "n" , and then print all of the (positive) even perfect squares less than n, each on a separate line. I want the method to be called something like this:

public void Squares(int n) {
}

I need the output to look something like this:

Example: if n = 40, your code should print

4
16
36

So I have been working for a few hours now and am really stuck.

This is what I have so far:

int count = 0;
int n = 4;
int max = n;
while(count < max) {
System.out.println(n);
n = n * n;
count++;

View Replies View Related

Program Is To Accept Number And Display New Number After Removing All Zeros

Dec 29, 2014

ex
Sample input:2340980
Sample Output:23498

this is the program i have tried but is dosent work

import java.util.*;
class zero
{
public static void main(String args[])
{

[Code]....

View Replies View Related

How To Create Simple Random Number Generator For Number Between 1 -10

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

I/O Arrays - Count Number Of Repetitiveness In String For The Number

May 19, 2014

//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones

import java.io.*;
import java.util.*;
public class Lottery2

[Code] ....

when I run it the array gets sorted but how do i keep the data in other words

what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.

View Replies View Related

Change Negative Number To Positive Number?

Nov 20, 2014

I am 4 weeks into my Intro to Java course and I am having a bit of trouble with my code. I need to make a program that will take a user inputted number, space the numbers out, then add them to a total sum. What I am having a hard time with is when I enter a negative number. I can't figure out what I need to do to have my program ignore the "-" in the string.

import java.util.*;
public class Week4_Programming_Problem
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int number, digit, sum=0;
char digitPos;

[code]....

View Replies View Related







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