How To Get A Program To Repeat X Amount Of Times Automatically
Oct 27, 2014
Ii am trying run a do while loop on java a specific amount of times for example if i were to type in "Enter number of years" and enter 4. i need the loop to execute 4 times or if i said 6 times then i would be 6. the program i have repeats it and takes it back to reentering "Enter number of years" i need it to execute by its self x amount of times. here is what i have so far
System.out.println("Enter the number of years: ");
years = keyboard.nextInt();
rainfall = generator.nextInt(10) + 1;
System.out.println("Year " + "rainfall amounts were");;
for (int months = 1; months <= 12; months++)
I am having is not being able to print out the diamond the amount of times the user enters (for example, when it asks how many diamonds, I enter a 2 and only one diamond comes out.)
import java.util.Scanner; public class Pattern5 { public static void main(String[] args) { // For this pattern program, ask the user how many diamonds // she would like to print to the screen. The following pattern is one diamond.
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; } }
My question is how can I make the program repeat until the user enters the number 4 to exit?
/** * Write an application for a furniture company; the program determines the price of a table. Ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany. The output is the name of the wood chosen as well as the price of the table. Pine table cost $100, oak tables cost $225, and mahogany table cost $310. Also ask the user to specify a
(1) large table or a (2) small table.
Add $35 to the price of any large table and add nothing to the price for a small table. Display the output. Your program must repeat until the user chooses to exit.
*/ import java.util.Scanner; public class Wood { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println ("Table Prices");
so I had to make a program that prompts the user to enter a loan amount and the years for the loan and I have the conversions and everything my only issue is that when the chart pops up it just looks like a bunch of numbers and its missing the column headers
for example
Interest Rate Monthly Payment Total Payment
import java.util.Scanner; public class InterestRate { public static void main(String[] args) { double monthlypayment = 0; double totalpayment = 0; Scanner input = new Scanner(System.in); System.out.println("Enter Loan Amount");
Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).
Java Code:
class Benchmark { public static void main(String[] args) { long endTime = System.currentTimeMillis() + 60000; int count = 0; for (int i = 0; System.currentTimeMillis() < endTime; i++) { double x = Math.sqrt(System.currentTimeMillis()); count = i; } System.out.print(count + " calculations per minute"); } } mh_sh_highlight_all('java');
I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?
I am trying to write a program that basically determines the max amount of units sold and displays it in a dialog box. Also, the program will display the winning sales associate out of 10. I have wrote the program successfully so far and I can see the maximum number of units sold displayed in the dialog box, but I cannot seem to link the winning sales person.
Here is the code I have typed so far.
//Program to find maximum of three number
import javax.swing.JOptionPane; import java.util.Scanner; public class Sales { public static void main (String[] args) { //Declare variables int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10; int large; int winner;
Recently I have missed a few weeks of my class due to family emergencies. Because of this I have missed very important lectures. My professor has assigned me the following assignment:
Prices Write a Java program that specifies three one-dimensional arrays names price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:
Total Price Amount
==== ==== ======
Under each column heading display the appropriate value.
I know how to display everything using printf, how to create the actual arrays and define the array size, but I am confused on how and what loop to use and how to construct it. This is what I have managed to write up so far:
import java.util.Scanner; // Imports the Scanner class import java.text.DecimalFormat; // Imports the DecimalFormat class
public class Prices { public static void main(String [] args) { double[] price = new double[10]; double[] amount = new double[10]; double[] total = new double[10];
// Create a new Scanner object Scanner keyboard = new Scanner(System.in); } //End of main method } // End of public class
I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) {
I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.
I am using java 1.7 sdk and pupy linux as OS. Below i am giving source code.
What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.
But what is happening is it shows welcome text and then directly Plzz wait..
Its not showing text Enter... because control is finished after last method gets executed.
My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.
public class BackgroundFrame extends javax.swing.JFrame {
public class PairOfDice { private Die die1, die2; public PairOfDice() { die1 = new Die(); die2 = new Die();
[Code] .....
I am struggling with the final part of my code to get the dice to roll 1000 times and tell me how many times a 7 was rolled. I am getting these errors in jgrasp
----jGRASP exec: javac -g PairOfDice.java
PairOfDice.java:34: error: <identifier> expected count = 0; ^ PairOfDice.java:35: error: illegal start of type for (rep = 1; rep <= 1000; rep++) {
My goal here is to create a program that will deny access to the browsers during certain times of the day. The research that I have done makes this out to be near impossible (using signal handlers in java). where to start, if its possible, or anything else im missing. (System is windows 7).
I am using ui:repeat tag to iterate over a list. Now in that I need to do some processing based on the current iteration index like we have in a normal for loop. I have to do some processing based on the current iteration index. How can I get that.
i have a client side program that grabs information about the computer it runs on. I want to have it grab the same info every so often, and check it against the original.
what can be used to do something like that? end game would be having it start up with the pc, then check periodically. if the values are different, send them to the database
I wanted to make a small program to move a small rectangle by pressing the WASD keys. The program works, except that when I hold a key to move the rectangle, after a second, auto-repeat starts up, and the rectangle motion accelerates. I want to prevent automatic repeat to activate, so that the rectangle moves at a constant speed when I hold a key and stops when I released. Here is the ButtonMotion classe :
I am trying to write a Random Number Generator that will not contain any repeat value in a given range
something this I have try so far
import java.util.Random; /** * This class is used to generate a * Range of Random Number in a range from int a to int b */ public class RandomNumberGenerator { public static void main(String[] args) { int[] arr=randomNummbers(1, 20); for(int j=0;j<arr.length;j++){
[Code]...
although this code generate random numbers but some values are also getting duplicate.So how to write a program for random number that will not repeat any integer in range?
I'm writing a JavaFX desktop app, and would like to make it automatically run after installation, but I'm not sure where to look to make this happen (or even if it's possible?). I have successfully created a .dmg installer using E(fx)clipse & Ant. Are there options I'm overlooking which I can use in the build.xml? or am I looking in the wrong place entirely?
The array size is fixed improve it to automatically increase the array size by creating a new larger array and copying the contents of the current array into it .I am using a course class and here is the code for the class
public class Course { private String courseName; private int numberOfStudents; private String[] students = new String[100]; public Course(String courseName)
[Code] ....
As you can see I have the array set to size 100, how do i make so it increments each time the user adds a student.
I am trying to get random shapes to generate automatically. I was able to get just three shapes to generate but nothing random. When I added the random code now only the frame shows up and no shapes. I also keep getting an error with frame.setVisible(true). It says identifier expected. Here is what I have so far:
Main program:
import javax.swing.*; import java.awt.*; import java.util.Random; public class ShapeGen { public static void main(String [] args) { //Create window and set title draw panel = new Draw();
[Code] ....
This is the draw program to generate random shapes:
import javax.swing.*; import java.awt.*; import java.util.Random; public class draw extends JPanel { public draw(Color backColor) { setBackground(backColor);
The program shall assign a new employee ID to the employee and display it on the screen.
The employee ID shall be generated by adding 1 to the largest employee ID already in the employee.txt data file.
You can see I've tried variations of identification++ but have not been successful. I've also tried to get the last or the highest identification in the arrayList but have not done that right.
public static void addEmployee() { String firstName = Validator.getString( sc, "Enter First Name: "); String lastName = Validator.getString( sc, "Enter Last Name: "); int identification = 0;
[Code] ....
I also can display all of the employees their identifications and their punches but I cannot narrow it down to searching one employee and displaying information for just the one.
-If the selected value is ‘I’, prompt the user to enter the employee’s ID number. -If ‘I’ is selected the display shall show the employee’s name and ID, list out each day worked in chronological order, the number of hours worked that day and a total number of hours worked in the two week period.
The report shall prompt the user to re-enter an employee ID of it does not exist in the employee file.
private static void displayReports() { System.out.println("Report"); Scanner sc = new Scanner(System.in); String action = " "; while (!action.equalsIgnoreCase("d"))