and what I want to do is simply run through a loop (Which I already made ) that will randomly just put this strings together.
So if the loop runs once it will return something similar to
00001011001101000110
The thing is that I don't want to return such a number as an String, I want it to be returned as a long.This was one of my recent attempts
/* Contains the genes or possible solutions to the problem
*/
public class Genes
{
/* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes
* The last 4 elements in the array represent + - * / correspondingly
*/
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};
[code]...
What can I do ? I want them the values returned to be of the long data type, but I don't want the binary numbers to be added together. I just simply want them to be placed one next to each other at random patterns
Write a program that declares and concatenates various strings. Declare strings for your first name, middle initial and last name, along with one for your address, city, state and zip. Make an additional string called firstLine, which will be a concatenation of first name, space, middle initial, period, space, and last name. Assign each of these strings a value, and then print the information in the following format:
First Line (First name Middle initial (period) Last name)
Address
City, State
Zip
For example:
John Q. Public
1234 Any Street
Cleveland, Ohio
44101
Now reassign the strings in the same program (Do not create a separately compiled program!) and repeat the printout for different information. When you are finished, your program will print out two groups as above.
The information should be placed into the seven separate strings, then a first line should be formed by concatenating first name, space, middle initial, period, space, and last name. The city and state line should be formed by printing city followed by a comma, a space, then the state (NOT by concatenation). This is so you can see different ways of making lines."
From robosoul's response at StackOverflow, I simply inserted a condition for negative integers (line 12). True enough, the code worked and I was able to trace (pen and paper method) how it is converting the 0 and positive integers to words.
However, I am a bit lost on how it is doing the conversion for negative integers. How it is successfully converting the negative?
in Operator/Literals, it says "There is no literal representation for binary numbers in C, C++, or Java." seems "0b11001" could reprensent binary numbers?
I am trying to make binary search tree...I am trying to construct the left part of binary search tree with root node set as 70...It is not working ...My code is
public class Node { /** * @param args */
int root; Node left; Node right; public void insertNode(Node node, int num) { //Node nodeRoot = this; //root of tree we have set to 70...constructing only left of tree with root=70
how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:
blue 18 blue 10 red 27 yellow 4
public class Rainbow{ private String color; private int size; public Rainbow(String color, int size){ this.color = color; this.size = size;
[code]....
I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers
import java.util.Scanner; public class CountStringNumbers { // show the number of Strings that were numbers . . .. public static void main(String []args){ int count = 0; int countNumbers=0; Scanner input=new Scanner(System.in);
[code]...
can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??
countNumbers++; } System.out.println("Type Something , , , and to end the the termination type STOP"); word=input.nextLine(); count++; } System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated "); } }
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");
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;
So I have to convert strings to double numbers and there can be no exception.
The strings that aren't numbers or do not fit into a set criteria have to be discarded.
When I try to write this I get an exception when a non-numeric is entered and the code stops.
What can I do? Also, am I finding the average of the array correctly?
import java.util.*; public class Grades{ public static void main(String args[]){ int arraycount = 0; final int SIZE = 10; int validArraycount = 0; final int ValidArraySize = 10;
I am trying to concatenate two arrays but on on compiling it is showing
Java Code: import static java.util.Arrays.*; class Mergesort { public static void main(String...s) { Mergesort r=new Mergesort(); int x[]={1,2,3,4,5,6}; int y[]={9,8,7,15,14,13,12,11};
The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
//main method that executes the java application public static void main(String args[]){ //declares variables
int digit; int base=2; int degree; double decimal; int binary_zero=0; int binary_one=1; //create scanner for object input
[code]....
The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.
I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:
aadafbd dsfgdfbvc sdfgyub fhjgbjhjd
my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).
I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.
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);
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);
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];
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];
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); } } }
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?
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();