Checking Array For Title - Exiting For Loop

Oct 4, 2014

i want to check my array for a title, if the title is there i want to call a method, if the title is not there i want an error message. I am not sure how to get this. i think my code would work if it didn't always finish the method. for example if true the method stops and does run whats after the for loop. but that isn't happening.

void markItemOnLoan(String title, String name, String date){
int i=0;
for (i = 0; i < numberOfItems; i++){
if (items[i].getTitle().equals(title)){
items[i].markOnLoan(name,date);
}
}
System.out.println("ERROR: Can not find that item. ");
}

View Replies


ADVERTISEMENT

Fibonacci Series Program - Exiting For Loop Early If Exceed Specified Number

Feb 13, 2015

I'm trying to change the code on a Fibonacci series program that would allow me to exit the loop early if I exceed a specified number. The user enters any 2 random numbers (which will be the 1st 2 no.'s of the Fibonacci sequence printed to screen) and then continues up to a 'limit' on the number of numbers set in code. Here's the code:

int[] array = new int[limit]; //Define an array whose length is set by an int value for limit!!
array[0] = x; //User supplies a int value for x which takes the 1st position in the array!!
array[1] = y; //...and an int value for y in the 2nd position!!
 for (int i = 2; i < limit; i++) //Start from the 3rd position of the array when carrying out calculations!! {
array[i] = array[i-1] + array[i-2];

[Code] ....

To exit the code/ 'limit' early if the array prints a number higher than 100, I tried putting a 'while' condition before the last line, as follows:

while (array[i] < 100)
System.out.print(array[i] + " ");

Can I even use a 'while' loop within an array, or is there some other way I need to integrate it?

View Replies View Related

How To Close JFrame Without Exiting Application

Apr 10, 2014

How to make a Jframe close without closing the whole operation, I started off using exit on close and changed it to hide on close and i also tried dispose on close for some reason it wont work. Here is what I have.

import java.awt.*;
import javax.swing.*;
public class GUILauncheralt{
public static void main(String[] args){
RetrieveWindow gui = new RetrieveWindow();
gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
gui.setSize(400, 200);

[Code] .....

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

How To Rename GUI Title

Feb 24, 2011

I have developed a java GUI project. I put wrong name for my project. after some time i found it and then correct by right clicking and click rename tab.

Now i run my gui it shows old project name in title. i didnt get my new project name.. how can i change it to new name

View Replies View Related

JSF :: Updating Primefaces TabView Title

Mar 5, 2014

I have a TabView that generates the numbers of tabs, titles and content based off of the selected project from another field. I have managed to get it to load the proper number of tabs and content, but the first tab title displays the title of the first tab from the previous query.

The jsf is:

<h:panelGroup id="equipmentWrapper">
<p:tabView effect="blind">
<c:forEach items="#{databaseViewHandler.deviceTypes}" var="deviceType">
<p:tab title="#{deviceType.key}">
<ui:include src="#{deviceType.value}"/>

[Code] ....

And the method handling the content and number of tabs:

public DatabaseViewHandler() {
deviceTypes = new LinkedHashMap();
}
public Map<String, String> getDeviceTypes() {
return this.deviceTypes;

[Code] ....

The method findAssociatedEquipment() is called when it recieves a selected project to display.

The command button calls the update for panelGroup "equipmentWrapper". It updates fine for the ui:include and generates the correct number of tabs in the correct order.

So for example the first query might only generate one tab for an 881 device. Then if you select a project that should have a 2911 and 2960 it will correctly load both, but the title for the first tab will retain 881. Should you select a third it will have the title 2911 from the second project.

View Replies View Related

JavaFX 2.0 :: TreeTable Can't Change Title

Mar 16, 2015

I change TreeTableColumn.text but I got a Exception
 
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException:
javafx.scene.control.TreeTableColumn cannot be cast to javafx.scene.control.TableColumn
    at com.sun.javafx.scene.control.skin.TableHeaderRow$10.invalidated(TableHeaderRow.java:277)

so I check TableHeaderRow . I find this method
 
private final InvalidationListener columnTextListener = new InvalidationListener() {
        @Override public void invalidated(Observable observable) {
            TableColumn<?,?> column = (TableColumn<?,?>) ((StringProperty)observable).getBean();
            CheckMenuItem menuItem = columnMenuItems.get(column);
            if (menuItem != null) {
                menuItem.setText(getText(column.getText(), column));
            }
        }
    };

why don't they use this

TableColumnBase<?,?> column = (TableColumnBase<?,?>) ((StringProperty)observable).getBean();

View Replies View Related

Displaying Icon And Title In Multiple Java Frames?

Jan 13, 2014

I developed a simple java gui . On running a frame opens with 5 buttons and each button opens another frame when selected. There are no errors and frames open and close as required however i see that only the main program frame has the icon and title that i assigned and the frames bieng called through the buttons have the default frame with java icon and no title although it's been specified in the code of these called frames. When these called frames are executed individually though the program the title and icon are displayed.

View Replies View Related

Program To Scrape All Title Tags From Large Sites

Apr 9, 2015

I am familiar with php, but I don't know Java. We need a program, that will be able to scrape large amount of title tags from large sites, fast. I've been trying Seo Spider by Screaming Frog, and Xenu's Link Sleuth, but these programs are not good enough. They hang up, they save all the data in RAM, I think, and after a relatively short period of scraping, they stop working, become unresponsive, and so on.

Somebody recommended me getting a custom made program in Java, which would be able to scrape title tags only, from large sites (I am talking 25 - 50 million pages or more). I was told that it would not have a graphic interface, or anything like that. Nothing like this is needed too, we just need to have title tags.

View Replies View Related

Search For Highest Number In File / Print Its Title And Value

Dec 9, 2014

In a text file, I have individual titles (starting with ">" character), and under those titles, I have calculated values for a Counter. I want to search the entire text file for the highest counter under every title. After I get the highest counter, I would like to print it's title, name of the counter, and counter value. Example of the code I already have:

int letterCounter;
String line;
if (line.startsWith (">")) {
bw.write ("");
bw.write (line);
} else {
//code that counts how many total letters (letterCounter) under title
}

I am just trying to use basic concepts.

Sample of my text file:

>gi 91206428 ref NP_001035160.1 seven transmembrane helix receptor precursor [Homo sapiens]
letterCounter is 43
>gi 157412240 ref NP_001094800.1 C1GALT1-specific chaperone 1-like [Homo sapiens]
letterCounter is 7
>gi 117938299 ref NP_001071105.1 RAB6C-like [Homo sapiens]
letterCounter is 109

Sample of desired output:

>gi 117938299 ref NP_001071105.1 RAB6C-like [Homo sapiens]
letterCounter is 109

View Replies View Related

Converting String To Title Case But Ignoring Specific Word

Feb 23, 2014

I need to turn some strings from:

'1-the-high-street'
to:
'1 The High Street'

But...

if string is
'the-dog-and-duck'

I want to achieve
'The Dog and Duck'
...whereby the 'and' is NOT converted to title case

My code as follows:

String propertyPageTitle = "1-the-high-street";
propertyPageTitle = propertyPageTitle.replace("-", " ");
propertyPageTitle = WordUtils.capitalizeFully(propertyPageTitle);
System.out.println(propertyPageTitle);

prints: '1 The High Street'

How could I handle the second scenario so it does not convert 'and' to titlecase?

View Replies View Related

For Loop Involving Array

Jan 29, 2015

As a result I need to get 6 66 666 6666 66666, but I'm getting a mistake. Can anb explain what's wrong?

Java Code:

public static void main(String [] args)
{

int[] sixes = new int [6];
for (int i = 0; i < sixes.length; i++)
{
sixes[i] = i * 10 + 6;
System.out.print(sixes[i]);
}

} mh_sh_highlight_all('java');

View Replies View Related

How To Do For Loop With Char Array

Apr 15, 2015

How can I display this result.aJohny

I have array contain numberi create new char array and i want to check if a number is >= 90 in array then input A at the same index in char arraythen second part i want to check if char array contain "A" then a = a + 1. 

The result is like this:

A: 5
B: 29
C: 38
D: 24
E: 12
F: 17
 
public class Test {
public static char[] grades(int[] getMarks) {
                        char[] grade = new char[getMarks.length];
                        for (int i = 0; i < getMarks.length; i++) {
                                    if (getMarks[i] >= 90) {

[Code] .....

View Replies View Related

How To Create Array Using Loop And Sort It

Mar 30, 2015

I am writing a program which writes down all possible equation y=a+b+c values from min to max (in reality this equation would more difficult, but here is just short example).

The problem is that my sorting code can't get access to full array in loop.

Is there any way to pass array to sorting code, or somehow change sorting code?

package pkg06;
public class Main {
public static void main(String[] args) {
double aS =-1;
double aE = 3;

[code]...

View Replies View Related

Using Do While Loop With Array For Phone Numbers

Apr 20, 2014

I need a phonebook that allows the user to input up to 100 numbers but stop when they want to. I have the code for the array and input and output. I thought I had the do...while loop correct for asking the user if they want to input another name but its not working, even when you input "N" it still keeps going. Here's my code.

import java.util.Scanner;
import java.util.ArrayList;
public class PhoneEntry2 {
int x;
char repeat;
final int maxContacts = 100;
String[] pNums = new String[100];

[Code] ......

View Replies View Related

Printing Each Value In Multidimensional Array Using For Loop

Dec 5, 2014

I want to print each value in the multi-dimensional array using a for loop but there is a problem.

Here is the script:

Java Code:

public class LearningJava
{
public static void main(String[] args) {
int[][] Grid = {
{12, 24, 36, 48, 60},
{1, 3, 5},
[Code] ....

Printing i: 0, x: 12
Printing i: 0, x: 24

Exception in thread "main" Printing i: 0, x: 36

Printing i: 0, x: 48
Printing i: 0, x: 60

java.lang.ArrayIndexOutOfBoundsException: 5
at LearningJava.main(LearningJava.java:11)

It's suppose to get the length of each array and print all the values in that array and then move to the next one.

I tried adding .length

Java Code: for(int x = 0; x < Grid[i][x].length; x++) mh_sh_highlight_all('java');

but then it doesn't work at all.

View Replies View Related

2 Dimensional Array Assignment With A Loop

May 5, 2015

I have a 2 dimensional array assignment with a loop, i'm supposed find the average score of each student from a grade record and find the average score for each test. I've been trying to do the assignment all day with no progress. This is what i have so far

public class SiuTest {
public static void main(String[] args) {
String [] stu= new String [5];
int [] [] grade= new int [4][2];
String hold;

[code]....

View Replies View Related

Counting Input Array - For Loop Statement

Mar 13, 2014

I have to take user input and then count how many times each number that the user input and print each one out. For some reason, I can't even get the for loop statement to print and it's pretty much the same as my other program except for the loop which is a little different.

//User inputs numbers between 1 and 100, program counts how many of each integer is and ends with a 0
 
import java.util.Scanner;
 public class occurrence {
 public static void main(String[] args) {
 //scanner/values
Scanner input = new Scanner(System.in);
int number = 0;
int c = 0; //array count
 
[Code] ....

View Replies View Related

Finding Array Index Number Through For Loop

Jan 29, 2014

int[] a = new int[7];
a[0] = 0;
a[1] = 10;
a[2] = 256;
a[3] = 57;
a[4] = 33;
a[5] = -154;
a[6] = 168;

[code]....

What program needs to find is the most biggest number. It does the job, but another task of the program is to find the index of that number . The second loop should do just that, but for some reason, as the loop goes further, it passes through the if statement even though answer "a[i]" is not equal to "answer". The idea is that if a[i] and answer are equal, the "i" should represent the index number.

View Replies View Related

How To Give Values To Array Objects Without Using Loop

Apr 3, 2014

The main method should creates a Student object with name as "Bill" and marks as {88,92,76,81,83} and print it.

Java Code:

class TestStudent {
public static void main(String args[]) {
Student1 st = new Student1();
st.name = "bill";
Student st1[] = new Student[6];
//This gives error
st1[].marks = {1, 5, 8, 9, 7, 6}; mh_sh_highlight_all('java');

View Replies View Related

How To Access Element Of Multi Dimensional Int Array Using For Loop

Jul 12, 2014

I have written following code.

I want to print all elements in Array to output here is my code

int[][] arr={{12,12,13},
{14,1223,14}};
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
{
System.out.println(arr[i][j]);
}
}

but I am getting following output

12
12
14
1223

how to print all elements of int array?

View Replies View Related

Trying To Find 3 Largest Numbers In Array Using Single For Loop

Feb 5, 2014

I am trying to find 3 largest numbers in an array using a single For loop but my following code is still showing randomly sorted numbers.

public class largest3 {
static int m, n, o;
static int array[] = new int[100];
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
array[i] = (int) (Math.random() * 100);

[Code] ....

View Replies View Related

Using For Loop To Populate Array With Random Double Values

Oct 26, 2014

Write a program that creates an array that can hold 9 double values that represent baseball batting averages for a starting baseball lineup. Use a for loop to populate array with random double values in the range of 0.00 to 0.500. Recall that "double" values are what Java calls "real" numbers. Use a second for loop to print the values in the array with one number per line. Finally, use a third for loop to traverse the array and find and print the maximum batting average in the array. Note: you will need to use String.format to control the precision of a double number when you print it- Here is my code so far:

public class P2F {
public static void main (String[] args) {
double [] player= new double [9];
//player[0]= Math.random();
for (int index=0; index < player.length; index++) {

[Code] ....

When I open the terminal window I get different variations of this [D@4545c5]. I would like to know all the things I am doing wrong.

View Replies View Related

Create For Loop That Randomly Assign Values To Each Element Within Array?

Apr 16, 2014

Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?

import java.util.Scanner;
public class ArrayExamples{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double exampleArray[] = new double[5];
System.out.print("Enter a Number: ");
int num1 = input.nextInt();

[Code] .....

View Replies View Related

Checking If Int Is Lowest Out Of 4?

Apr 30, 2014

I'm trying to find the int with the lowest value, and I only know how to set it up like this:

Let's say x1 is the lowest.

int x1, x2, x3, x4;
 
if (x1 < x2 && x1 < x3 && x1 < x4) System.put.println("x1 is the lowest value out of those 4");

Is there a way to shorten this at all? (It's alright if there isn't, just looking for shortcuts)

View Replies View Related

Checking Whether Int Is Prime Or Not?

Oct 25, 2014

//checks wether an int is prime or not
public static void main(String[] args) {
int n = 17;
boolean prime = true;
if (!(n==2)) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0);

[Code] .....

View Replies View Related







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