Alternating Numbers Of Two Sequences
Jul 6, 2014
I am trying to alternate the numbers of two Sequences. Right now getting an infinite loop. Here is my method.
public ArrayList<Integer> merge (Sequence other) {
for (int i =0; i < other.values.size(); i++) {
if (i%2==0) {
for (int j =0; j < values.size(); j++) {
[Code] .....
View Replies
ADVERTISEMENT
Mar 4, 2015
I've created a class that extends FilterReader, that is to be used to find certain sequences of letters. I plan on using this code to demonstrate an observer, observable design pattern later on. Here is my code:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Arrays;
public class CaroReaderV2 extends FilterReader {
[Code] .....
Now my question is, how do I go about testing this in a main class? How would I pass in a reader to the constructor? How would I make sure that everything is working correctly?
View Replies
View Related
Aug 8, 2014
I've started creating a simple game in Java, but I'm still a beginner, so now I'm stuck. I wanted to make moving character by fast alternating arrow keys, but I don't know how. I can make a boolean variable, which disables moving by pressing the same key again, but the player can just hold the key and character is still moving. I thought about changing position of character when the key is pressed, instead of increasing speed, but then the movement wouldn't be smooth. I think this may sound incomprehensible, so I will add a link to game like an example of what I mean.
[URL] ....
View Replies
View Related
Aug 3, 2014
I've started creating a simple game in Java, so now I'm stuck. I wanted to make moving character by fast alternating arrow keys, but I don't know how. I can make a boolean variable, which disables moving by pressing the same key again, but the player can just hold the key and character is still moving. I thought about changing position of character when the key is pressed, instead of increasing speed, but then the movement wouldn't be smooth. I think this may sound incomprehensible, so I will add a link to game like an example of what I mean.
Play Mini Sports Challenge game online - Y8.COM
View Replies
View Related
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
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
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
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
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
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
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
Jul 1, 2014
I wrote a program to find the sum of first 10 numbers using the for loop... here is the piece of code
public class Sum {
public static void main(String[] args) {
int sum = 0;
for (int N=0; N<= 10; N++) {
sum = sum + N;
}
System.out.print("The sum of first 20 numbers is " + sum);
}
}
I tried to write the same program using the while loop but with no success. How can i write this using while loop?
View Replies
View Related
Jun 4, 2014
I don't know what I did to screw this up, but I had this code working to increment each employee ID by one every time a new employee was added. I tried to move the whole employeeID and newEmployeeID elements out of the constructor because everyone keeps telling me how bad it is to have those in the constructor. However, now, every time I add an employee, their ID number turns out to be 0. I have two other aspects of this project that are due soon, and if I can't fix this part, I won't be able to move forward to the other parts (which I am also stuck on at this point). The codes that are being used are as follows:
import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.text.NumberFormat;
public class Employee
{
// instance variables
private String firstName;
private String lastName;
private int employeeID;
static int newEmployeeID = 0;
[Code] ....
View Replies
View Related
Apr 3, 2014
how to add two numbers using RMI..This very simple example is taken from Chapter 24 of "Java 2: The Complete Reference" by P.Naughton and H.Schildt.The example is overly simplified but it still illustrates the basic steps in creating an RMI distributed program.
This example provides step-by-step directions for building a client/server application by using RMI. The server receives a request from a client, processes it, and returns a result. In this example, the request specifies two numbers, the server adds these together and returns the sum.(Of course, this program is intended only to illustrate the basic RMI mechanism.)The next subsections provide main steps in writing an RMI program
Define an interface that declares remote methods.The first file AddServerIntf.java defines the remote interface: it includes one method that accepts two double arguemnts and returns their sum. All remote interfaces must extend the interface Remote, that defines no methods: its purpose is simply to indicate that an interface uses remote methods.All remote methods should throw a RemoteException
import java.rmi.*;
public interface AddServerIntf extends Remote {
double add(double d1, double d2) throws RemoteException;
}
Implement the remote interface and the server
The second source file AddServerImpl.java implements the remote interface:
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject
implements AddServerIntf {
public AddServerImpl() throws RemoteException {
}
public double add(double d1, double d2) throws RemoteException {
return d1 + d2;
}
}
All remote objects must extend UnicastRemoteObject which provide the functionaly that is needed to make objects available from remote machines. The third source file AddServer.java contains the main program for the server machine. Its primary function is to update the RMI registry on that machine. This is done by using the rebind() method of the Naming class (it is in java.rmi API). That method associates a name with an object reference.
import java.net.*;
import java.rmi.*;
public class AddServer {
public static void main(String args[]) {
try {
AddServerImpl addServerImpl = new AddServerImpl();
[code]....
Develop a client (an application or an applet) that uses the remote interface..The fourth source file AddClient.java implements the client side of this distributed application. This program requires 3 command line arguments: the IP address or name of the remote server, and two numbers that are to be summed.
The application forms an URL string using the rmi protocol, the first command line argument and the name "AddServer" that is used by naming registry of the server. The the program calls the method lookup() of the Naming class to find a reference to a remote object. All remote method invocations can then be directed to this object.The client program illustrates the remote call by using the method add(d1,d2) that will be invoked on the remote server machine from the local client machine where the client runs.
import java.rmi.*;
public class AddClient {
public static void main(String args[]) {
try {
String addServerURL = "rmi://" + args[0] + "/AddServer";
AddServerIntf addServerIntf =
[code]...
If you do not have an Internet connection, you can run all programs of this example on your local machine (both server and client). In this case, you can run
java AddClient 127.0.0.1 567 999
to use the "loop back" address (127.0.0.1) for the local machine. This will allow you to test the entire RMI mechanism without actually having to install the server on a remote computer.
View Replies
View Related
Sep 27, 2014
The first problem is that the numbers don't round in IntelliJ.
Example: ('s in Dutch)
Geef de vorige kilometerstand: 125
Geef de huidige kilometerstand: 900
Geef het aantal getankte liters: 50
Verbruik voor 775km: 6.451612903225806/100km
That 6.4516..... is the problem, how can I make it 6.45/100km?
View Replies
View Related
Apr 3, 2014
how to sum up two numbers of fractions?
View Replies
View Related
Feb 12, 2014
/*
* Put your documentation header here.
*/
import java.util.Scanner;
public class Lab5{
/**
* Returns an integer whose value is a^3 (a cubed).
* @param any integer to be cubed
* @return a^3 (a cubed)
[code]...
The last part with int a-j...... Is there a better way of doing this, like possibly putting into a loop and showing output from maybe a single piece of information?
View Replies
View Related
Nov 19, 2014
I was trying to get sum of numbers between two given integer and managed to do it.
public int sum(int a, int b) {
int sum=0;
while(a <= b) {
sum+=a;
a++;
}
return sum;
}
in here; when I enter the values i.e 2 and 5, it calculates 2+3+4+5 and gives me the result 14.
my question is, how could I exclude a and b in this calculation ( in this case exclude 2 and 5 and return 3+4 )
Bonus question ; how could I only calculate the odd (or even) numbers between those integers?
View Replies
View Related
Sep 7, 2014
program that calculates and prints the sum of all numbers between two limits as the user types. Like if the user types 1 and 10 on the upper limit, it prints the following text: "1+2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55".
View Replies
View Related
Apr 14, 2014
how to determine if an integer is even or odd by using a boolean method. I think I have the method right, but it's calling the method into the main that has got me stumped.
import java.util.Scanner;
public class Odd_Even {
public static void main(String[] args) {
//Scanner, variables
Scanner input = new Scanner(System.in);
int number;
[code]....
View Replies
View Related
Dec 3, 2014
I want to make app in netbeans. When i write numbers in JTextField like 1,2,3,4,5,6... it should show me in JOptionPane information window result of ODD numbers.
View Replies
View Related
Sep 26, 2014
I need to add two integers in the same row of a file, separated by tab
my file abc.txt has the following entry
12 123
15 456
My program needs to add 12 with 123 and 15 with 456
I am being able to split the two entries in a row and convert them to integer but i dont know how to treat them as separate numbers and add them. For example if i try to add then 12 adds with 12 and 123 adds with 123. wheres it should be 12+123
Here is my program
import java.io.*;
public class test {
public static void main(String[] args) {
String s = "";
FileInputStream finp = null;
[Code] .....
View Replies
View Related
Nov 18, 2014
I have been struggling to find out what to change to allow my code to find the GCF of two numbers. The instance variable in the class is num, so I need to find the GCF of a and num. It works for the example problem of 25 and 15, returning 5, however it will not work for other problems.
public int findGCD(int a)
{
int result = 0;
int newNum = num;
if ((a > num) && (a % num != 0))
[Code] .....
View Replies
View Related
Nov 5, 2014
I think the problem in this is that the variable max is initialised as 0. Afterwards it remains in the while loop only, so the output is always 0. I dont know how to bring the last max value out of loop and print it.
import java.util.Scanner;
/**
*
* @author
* @version
*/
public class TEST1
[Code].....
View Replies
View Related
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
View Related
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