Recording Number Of Times All Runs Of Heads Occur

Jan 4, 2015

How do I record the number of times all runs of heads occur. Ex.

Length Number of runs of heads
1 --------------------3
2 --------------------2
3 --------------------0
4 --------------------1

public static void main(String[] args)
{
int [] coinToss = new int[TOSSES];
int longestRun = 0;
int run = 0;
for(int i = 0; i < coinToss.length; i++)
coinToss[i] = toss();

[Code] .....

View Replies


ADVERTISEMENT

Count The Number Of Division That Occur

Feb 4, 2015

I am using count++ in my program in order to count the number of division that occurs. It works but outputs:

The number of divisions is 1
The number of divisions is 2
The number of divisions is 3
The number of divisions is 4
The number of divisions is 5

All i want is the last line. How do I solve this?
 
import java.util.Scanner;
public class Program3
{
public static void main(String [] args)
{
int div;

[Code] ....

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

How To Print A Character Random Number Of Times

Oct 26, 2011

I'm trying to write a method that will print a string of a random number of X's (from 5 to 20) on a line, then another number of X's on the next line, etc. until the random number = 16.

I have to use while loops and probably fencepost algorithms. I'm confused with how to print the number of x's the random number of times over and over.

Right now, I'm pretty sure my for loop is wrong or unnecessary.

So far, this is my code:

public static void randomX() {
int x = 0;
while (x != 16) {
x = (int)(Math.random()*20) + 5;
for (int i = 0; i <= x; i++);
{
System.out.print("x");
}
}
}

View Replies View Related

How To Find How Many Times A Number Appears In Array

Dec 7, 2014

This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....

a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.

Java Code:

public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;

[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

Recording And Printing From Large Test Array?

Mar 22, 2015

I have a program that works, but I would like to know an easier way to record and print from a large array.

Here is what I have

package pa2;
import java.io.IOException;
public class PA2Delegate {
//long[] array = new long[100000];
int arraySize = 100000;
int iterations = 9999;
Long[] array;

[code].....

View Replies View Related

Count And Return Number Of Times Integer Occurs In Array

Nov 16, 2014

I have problems getting the right number of times for each number of the array. Here is my code:

public static void main(String[] args) {
int[] a = { 3, 13, 5, 9, 13, 6, 9, 13, 2, 3 };
int num = 3;
int count = numbers(a, num);
for (int i = 0; i < a.length; i++) {

[Code]...

View Replies View Related

Count And Display Number Of Times Specified Character Appears In String

Mar 7, 2014

Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)

Example:
Enter a string: "Hello, JAVA is my favorite programming language."
Enter a character: e
The number of times the specified character appears in the string: 3

I don't even know where to begin I've only got this

import java.util.Scanner;
 public class letterCounter {
 public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String myString = sc.nextLine();
System.out.println("Enter a letter");
String letter = sc.nextLine();
}
}

View Replies View Related

Coin Classes - Count Number Of Times Head And Tail Appear

Mar 26, 2014

I am trying to flip a coin 1000 times and make the driver class count the number of times a head and tails appear. However, I am having some trouble trying to figure out the error:

package Week5;
import java.util.Random;
public class Coin {
private int heads;
private int tails;
private int face;

[Code] ....

I was able to print out the generated numbers, but java will print either heads or tails a thousand times and count that as 1000 and nil for the other probability...

View Replies View Related

Flip Function - Making Coin Stop On Random Heads Or Tails

Nov 19, 2014

I cannot figure out why my buttons don't work. I believe my problem is in the flip function. I am very new to programming and I am about as good at code logic as I am at real logic lol. Also I am lost on how to go about making the coin stop on a random heads or tails.

Coin cF;
void setup() {
size (600, 600);
cF = new Coin(0,0,0);
}
void draw() {
background(100,100,100);
//Coin(int lX,int lY, int cSize)
//location(int l_x, int l_y)
//flip()

[Code] ....

View Replies View Related

Accept List Of Integers As Parameter And Return Number Of Times Most Frequently Occurring Integer

Nov 20, 2014

Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage.

If the list is empty, return 0.

View Replies View Related

Letters Of A String That Occur From Second Half Of Alphabet

Feb 11, 2014

Write a method named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.

View Replies View Related

Program Runs Differently When Executable Jar

Jan 27, 2014

I have a little application that I made, it requires that I save data to a file in data/coins.cdp. When I run the application with java myProg in the terminal everything is correct, when I create the executable jar and run java -jar myJar.jar or ./myjar.jar everything also works. Even if I copy the jar to a different location, and run it through the terminal, it still works fine. Things get weird through when I copy the jar to a new location and double click on it, because then no folder gets created and no file is written.

Why is that?

View Replies View Related

How To Override Comparing Method To Sort By Runs

Mar 16, 2015

I have an ArrayList, based on the class which stores cricket players, their names and runs scored.When I use the Collections.sort() method my arraylist is sorted alphabetically by forename.how to OverRide the comparing method to sort by runs, and thus the code I use to sort the list?

View Replies View Related

When Code Runs - Images Are Not Showing Up In Frame

Apr 27, 2014

I'm using the book "How to Program in Java 9th Edition". The following is code from that book. I'm using eclipse. When the code is run the images are not showing up in the frame. The images are located in the directory with the java file and I have tried using the fully qualified image locations with no success. I've looked around on the web but can't see any reason why this code won't work. The code compiles and no errors are reported.

// Fig. 9.13: LabelDemo.java
// Demonstrates the use of labels
package Fig9_13DisplayTextImagesWithLabels;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JFrame;
public class LabelDemo

[code]....

View Replies View Related

Convert Jar That Runs Off The Command Prompt Into Executable?

Aug 1, 2014

I was wondering if their is an easily explainable way to convert a jar for a text-based game that runs off the command prompt into a executable. I would guess there probably is not and the game would have to run off of completely different commands, but I thought it couldn't hurt to ask.

View Replies View Related

Exporting A Java Program From Eclipse That Only Runs In Console

Oct 11, 2014

I have recently revisited a program I wrote a few years ago, that runs absolutely fine in the console in Eclipse. However, when I export it as a Runnable Jar File, then open the file on my Desktop, nothing happens.How do I get the program to export so that when I open the file, a window opens that acts as the console (so the program can run in it)?

View Replies View Related

Application Runs In Eclipse Console - How To Make It Stand Alone

Jan 12, 2012

I have a single class application which works well in the Eclipse console. But how do I turn it into a Jar file?

View Replies View Related

Validation Loop That Runs Until User Enters A Valid Binary

Nov 17, 2014

I'm trying to do a user validation loop that runs until the user enters a valid binary, q, or Q. I think the rest of my program should work as intended, but here is the areas of concern:

public static boolean isBinary(String num) //Check if the entry is binary
{
for(int i = 0; i < num.length(); i++) {
if(num.charAt(i) != 0 || num.charAt(i) != 1){
return false;

[Code] .....

The program runs without errors otherwise.

View Replies View Related

Baseball Team - Calculate Total Amount Of Home Runs Hit By Batters

Mar 24, 2014

So I have a class called Team that is a collection of players and managers for a baseball team, and one of my required methods is to calculate the total amount of Home Runs hit by the batters. Now along with the Team class I have an abstract Employee class, an abstract Player class and a Batter class that extends the Player class I thought this would be fairly easy but it is coming out to be pretty hard my code is as follow:

class Team {
public int _numPitcher;
public int _numBatter;
public String _manager;
public ArrayList<Player> team;
 
[Code] ....

The total salary works awesome but for some reason when I try and call up how many home runs a player has it wont call correctly I get this red line under my code that says: The method getHomeRuns() is undefined for type Player. I am trying to call this from the batter class which is an extension of the Player class...

View Replies View Related

Writing Output Of Two Different Java Class Files To One Txt File While Program Runs

Jul 20, 2013

So I am trying to write the output of two different java class files to one txt file while the program runs.  The file name is determined before the program is ran, through the command prompt as arguments.  How can I get the second class file to edit the same txt file without running into compile errors.
 
For right now I'm just going to send everything that the second file outputs to a message String variable, so that the Main class outputs to the the text file.  I still want to learn how to write to the same text file directly from the second class file.
 
import java.io.*;
public class Test{
    public static void main(String[] args) throws IOException{
        int x;
        //create a new file internally called doc.  But externally labelled the user input
        File doc = new File(args[0]);
        if (doc.exists()){

[Code] .....

View Replies View Related

JavaFX 2.0 :: Create Implementation Of Service Class That Runs On Particular Time Everyday

Jun 23, 2014

I tried using ScheduledService but  the delay and period fields accepts a Duration object. I want the Service to run at exactly 6.00 pm everyday.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

How To Print String Only Five Times

Feb 11, 2015

I can't figure out how to print this string only five times. I tried to use the * operator, but that doesn't work with strings apparently, unles i'm not importing correctly.
 
import java.lang.String;
public class Looparray
{
public static void main(String args[] {
for (String myStr= "Hello there!";;) {
System.out.print (myStr);
System.out.print("
");
}
}
}

View Replies View Related

JSF :: Saving 2 Times One Form

Feb 22, 2014

I'm trying to save to a table in a database that has only 2 fields, (id, nota) . I want to save the data several times just to click on "save" one look . The code that I have is this:

<h:form id="frmPerso" style="font-size: 13px;">
<h:outputText value="Id 1" />
<h:inputText value="#{vistaEjem.notas.id}" />
<h:outputText value="Nota 1 " />
<h:inputText value="#{vistaEjem.notas.nota}" />

[Code] ....

I was told to use a foreach or for the insertDatos, but not as used..

View Replies View Related







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