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 :
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++)
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");
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?
Code is supposed to count number of Words in a String between A-Z and a-z, i am aware there are many methods to do this more efficiently, but i would prefer to do it using the methods shown.
class // Purpose : 1) Write a program which will input a string from the //keyboard, and output the number of separate words, //where a word is one or more characters separated by //spaces. Your program should only count as words groups //of characters in the ranges A..Z and a..z // { public static void main(String args[])
I am writing a Java permutation program, it takes in N and k and gives k amount of combinations based on N length.
That portion works, but the portion I have that does not work is when k is greater then 1, the array is then then printing strings out of index.
The perm algorithm ends on index - 1 for moving characters but then I push all those characters into an Array List, I would think I could print them off however I want from there but that is not the case. I'll include the minimum amount of code possible.
//permString = 1234 or something, it doesn't matter //Use Case N = 4 k = 3, prints out 123,124,132,134 ect //Use Case N = 4 k = 2, error index out of range but only on the printing function; the perm function doesn't take k and //is based on length //the "" is just an empty string permNow("", permString); }
I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.
Below is where I create a matrix of buttons via Swing
public class View extends Mybuttons{ private static final long serialVersionUID = 1L; JFrame frame; JPanel matrixPanel, optionsPanel; Mybuttons[][] matrixBtn;
Later in this class:
JPanel matrixPan(){ matrixBtn = new Mybuttons[25][25]; JPanel panel = new JPanel(); panel.setSize(550,550); panel.setLayout(new GridLayout(25,25)); //creating a 25x25 matrix of buttons
[Code]...
In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).
private Mybuttons getUnvisitedChildNode(Mybuttons b){ //example of some of the things I have tried int x= Mybuttons.getComponentAt(b); int y= Mybuttons.indexOf(b); int j=0; return b; }
Ok, so I'm just trying to write a basic little program that reverses the letters in someone's name. I thought I had it down, but I guess not. Here's the code, and the error I'm getting is:
java.lang.StringIndexOutOfBoundsException: String index out of range: 11 (in java.lang.String) (11 is the length of the name I'm inputting) import java.io.*; import java.util.*;
So I am working on an assignment and ran into an annoying bug. Basically i have a menu that accesses an ArrayList of Videos which may or may not be read from a file, one of the options of the menu is to edit an existing Video. For this I ask the user for the number of the video and it is checked against the list of video numbers if it returns a match, the method gets the index of the Video object and stores it in a temporary variable the user is allowed to edit the details and the object is put back into the ArrayList using the variable and the ArrayList's set() method
My problem is that once i finish editing the details of a video it gives me a indexOutOfBounds exception
On further investigation using a method that goes through the index of every object in the ArrayList using indexOf() i found out that every single object has been given the index of -1 and not 0,1,2,3 etc.. This is my first error and have not expierenced any other before.
The objects do exist because I have read them from a file. I can also add new Objects and view them successfully but they still have the same index . I have checked my syntax and everything and no errors, this happens at run time only.
I have even created some other ArrayLists seperately and debugged them and their index order is fine. I am too far into this project to start over. I've also tried cleaning the project(my IDE is Eclipse).
Im working on my homework and it mentioned element for one exercise and an index in another, what is the difference, If Any, Between An Element And An Index?
If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need
I'm new to java and I write a simple "Five in a row" game. I have a fixed 13*13 board which contains 169 buttons in an arraylist. Everytime player clicks the button the game set a value of 'x' or 'o' to the arraylist name value. And I have a method named isWon() to check if the it is won or not after player click the button. The game sometime gets and index out of bound exception when checking for whose win.
ArrayList<Character> value = new ArrayList<>(); constructor() { for (int i = 0; i < 169; i++) {
I can't even run the program, because it gives me index out of bounds exception but what exactly went wrong.
I feel that even after it's able to run it will be totally wrong, but one thing at a time /*Write a method called longestSortedSequence that accepts an array of integers as a parameter and returns the length of the longest sorted (nondecreasing) sequence of integers in the array.
For example, in the array {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12}, the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207), so your method would return 4 if passed this array. Sorted means non-decreasing, so a sequence could contain duplicates. Your method should return 0 if passed an empty array.
*/ public class ten { public static void main(String[] args) { int[] arr = {3, 8, 10, 1,9, 14, -3, 0, 14, 207, 56, 98, 12}; longestSortedSequence(arr); System.out.println(longestSortedSequence(arr));
How could I check if an index is exist in an array list? I mean, I should enter an integer and it should return me a boolean result that saying whether if that entered value is an index or not.
I am just studying over ArrayLists and i have encountered a problem, i'm trying to get the index of an element but it keeps returning -1. Here's the code
Java Code:
import java.util.ArrayList; public class PhoneEntry { String name; String phone; public PhoneEntry(String name, String phone) {
[Code] ...
I know the list is not empty because it returns a size.
I searched online for this error and found out it's because the array is smaller than the index but I am not sure how I can fix this error....
public Lamborghini[] getCarsWithHorsepowerRange(double lowHP, double highHP){ int i = DEFAULT_ZERO; Lamborghini[] carWithinHPRange = new Lamborghini[i]; for (Lamborghini lambos : inventory){ double horsePower = lambos.getHorsepower();
[Code] ....
I tried
Lamborghini[] carWithinHPRange = new Lamborghini[i+5];
//which works sometimes because once I boost up the range and so there'll be more result then the error came up again....