While Loops And Conditional Breaks?

Feb 12, 2015

public class dowhile2 {
public static void main(String[] args) {
int i = 1;
while(i <= 100){
System.out.println(i);
if(i == 50){
break;
}
i++;
}
}
}

I just want to know how to count this lines of codes. Because if I place for example i++ further up the code or the system.out.println a bit lower the result will be 1-49 or 2-50 and not the goal that is 1-50.

I want to know how to think and count. Why do i get 2345678.........50 and not 12345678........50 or 12345678.....49, thats the question.

View Replies


ADVERTISEMENT

XML :: Conditional Formatting On Subtotal

Dec 2, 2013

I found the XML for Total as below:
 
<saw:edgeLayer type="column" columnID="c523314f1e2a401c3">
<saw:levels>
<saw:level>
<saw:displaySubTotal id="t1" subTotalPosition="before">
<saw:memberFormat>
<saw:displayFormat>

[Code] ....

It shows some Error Message as "DXE compiler error. No table 'GTGT' found in DXE. Source name: DxeAPI. XML: None". It it possible to add some condition for Grand Total? If so, how I alter my XML??

View Replies View Related

Style Preferences For Conditional Returns?

Oct 21, 2014

I have a routine that returns a boolean. If any of a series of tests fails, the routine returns false, otherwise it returns true. For example, the routine might test for whether or not an integer is both odd and greater than 99, thus:

public boolean oddAndOld(int x)
{
if (x % 2 == 0)
return false;
if (x < 100)
return false;
return true;
}

I like the above because it suggests that "true" is the condition that applies if the incoming parameter meets all the required criteria. But I've sometimes seen this style used:

public boolean oddAndOld(int x)
{
if (x % 2 == 0)
return false;
if (x < 100)
return false;
else
return true;
}

I like this less because, among other things, if that last criterion is removed, the "else/return true" must be moved up into the immediately preceding test (or else leave some funny whitespace, depending on how you go about removing the departing "if" statement), but it does avoid suggesting that "return true" is hard-coded (that is, it reinforces that "true" is a conditional return value, not inevitable).

View Replies View Related

Creating A Conditional Boolean Variable

Nov 26, 2014

I am new to java and this seems like it has to be really simple, but so far I am unsuccessful. I want to create a boolean value if a certain condition is met. I need my application to compare who is logged in to my web app with the value for who created a particular report.

I retrieve the creator of a report in report.getCreatedBy() and I can display the current user with user.getName(). I need my application to determine if the person logged in is the same as the createdBy value and then set isAuthor() = true

if (user.getName().equals(report.getCreatedBy())) {
isAuthor = true;
}
else isAuthor = false;

Then I want to user the isAuthor true or false to display certain information in my jsp. That part I can handle, just not sure what I am missing / have incorrect from above.

View Replies View Related

Code Breaks After Upgrading To Java 8?

Jan 22, 2015

We recently upgraded to JDK 8. Since then, a section of code in a jsp file breaks. The code is this:

ArrayList all = new ArrayList();
final List tsd = timeSeriesBean.getTSData();
all.addAll(tsd); 
Collections.sort(all, new Comparator() {
public int compare(Object o1, Object o2) {
TSData t1 = (TSData)o1, t2 = (TSData)o2;
int res = t2.getDate().compareTo(t1.getDate());

[code]....

The error message is this:

An error occurred at line: 65 in the jsp file: /TS/VerifyImportTSData.jsp The type new Comparator(){} must implement the inherited abstract method Comparator.thenComparing(Function, Comparator)
 
64:
65: Collections.sort(all, new Comparator() {
66: public int compare(Object o1, Object o2) {
67: TSData t1 = (TSData)o1, t2 = (TSData)o2;
68: int res = t2.getDate().compareTo(t1.getDate());

just trying to maintain some old java code that I can support until it is rewritten.

View Replies View Related

JSF :: Page Content In OUTLOOK Body Not Getting Breaks

Jun 3, 2014

I have a requirement. I got a JSF page(parent page). When a button(say SEND EMAIL) is pressed, an email window (OUTLOOK) will be displayed as a popup. I have to populate whatever the text data of parent page as the body of the mail.

I am using mailto method : eg :

Here is my code:
==============
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest origRequest = (HttpServletRequest) context.getExternalContext().getRequest();
context.getExternalContext().redirect(String.format("mailto:"+mailTo+"?subject=" + subject +"&body=" + body + "&cc="+mailCc+""));

till here it is fine..

My problem is body part is not getting breaks. I have tried
, ,
, <br>, <br></br> etc.. what ever stuff i found in google..

E.g. my email body looks like below.. it consists of url link also.

====================================================
Hi,

This is to inform you etc... ,

Please follow this Hyperlink link to navigate to your page.. etc.

regards..

======================================================

View Replies View Related

How Boolean Finished Is Set To False And Breaks While Loop

Sep 11, 2014

I'm having trouble understanding how this loop is broken, I can't understand how the boolean finished is set to false and breaks the While loop.

public void run()
{
char answer;
boolean finished = false;
while(!finished)// when false loop is broken

[Code] ....

View Replies View Related

Moving Executable Jar Breaks App Save Function

Apr 1, 2014

I've been trying to deploy my desktop application as an executable jar file but I'm facing the following problem: Whenever I move the jar file from its original build location, my application becomes unable to write to its external files. I initially thought the problem was path related; however, when moved the app can still load data from these files.
 
The solution is probably simple but for some reasons I've yet to find it .
 
The app consists of a jar file and a folder named "files" containing text files (such as library.data) to which serialized objects are written.
 
I wouldn't be surprise if the problem has to do with the xml build file, but all modification I've tried so far have failed. If it is likely that it is the problem, I'll be happy to post a copy of it upon request.
 
public static void saveLibraryToFile() {
    File file = new File(System.getProperty("user.dir")+"fileslibrary.data");
    if (file != null && file.exists()) {
        library = new Library(sortedAccounts, accountCategoriesMap, accountCategoriesList);
 
[Code] ....
 
A mostly complete set of the relevant codes I'm using, including the full Ant xml file, can be found at : [URL] .....

View Replies View Related

JSP :: Loops In Dropdowns

Dec 5, 2014

I'm working on an old site that we have, I'm adding a couple dropdowns to our forms.With a connection to our database I can pull in values for selBaseCurr, But it's not pulling any values into the second dropdown for selTargetCurr...Am I missing something in the while loop?

<select title="Select currency to convert from" id="selBaseCurr" name="selBaseCurr">
<% while(rs.next()){%>
<option value=""><%= rs.getString("CURR_CODE") %></option>
<%} %>
</select>
<!-- /base -->

[code]....

View Replies View Related

Do While Loops With Chars?

May 28, 2014

here I have a do-while loop. When I push a button, then press enter, the program should do stuff, then ask me for another key. If I press any key but q, it repeats itself. If I press q then enter, it should end the loop. But then when I press q then enter, it still does the functions in the do-while loop.

Java Code:

Scanner kb = new Scanner(System.in);
System.out.print("Press any key to start.");
String letter = kb.next();
do
{
stuff
System.out.print("Press any key to call another number or press "q" to quit.");
letter = kb.next();
}while(!letter.equals("q") || !letter.equals("Q")); mh_sh_highlight_all('java');

View Replies View Related

While Loops Within If Else Statements?

Dec 19, 2014

What I'm trying to do below is to say if (adultTickets > 0) I want to bypass the studentOAP tickets question and go straight to the question about dinner. But if (adultTickets ==0) I want to go to the studentOAP question and then if the (studentOAPTickets >0) to go to the question about dinner. But if the (studentOAPTickets ==0) I want to go straight to the question about the contact number.

System.out.print("How many adult tickets do you require? ");
int adultTickets = 0;
boolean validAdultValue = false;
while (validAdultValue == false) {
if(aScanner.hasNextInt())

[Code] ....

View Replies View Related

For Loops With If Statement?

Nov 21, 2014

i'm confused about the if statement part because int i = 0 is set to zero but how can you get the remainder if int i is zero?

for (int i = 0; i < 200; i++) {
if (i % 12 == 0) {
System.out.println("#: " + i);
}

explain to why it output like this?

#: 0
#: 12
#: 24
#: 36
#: 48
#: 60
#: 72
#: 84
#: 96
#: 108
#: 120
#: 132
#: 144
#: 156
#: 168
#: 180
#: 192

View Replies View Related

While Loops And Strings

Jan 3, 2014

So the while loop I am trying to use is:
while( type != "EXIT" ) {
type = input.next();
}

The problem is that typing in EXIT doesn't end the loop like I want it to. I also tried input.nextLine(); but neither of them work. The loop is being used to fill an ArrayList so the number of elements can change based on how many they want. What am I doing wrong, or what alternatives do I have?

Seems I need to use !type.equals("EXIT")

View Replies View Related

Nested For Loops

May 15, 2014

how a nested for loop increments the outer loop and then the inner loop and then when it runs the inside code.I've ran the program a few times but I'm just not understanding it, need little narrative to it?

for(int i=0; i < 5; i++){
System.out.println("i - " + i);
for(int j=0; j < i; j++){
System.out.println("j - " + j);
count++;
}
}

View Replies View Related

Integer Or Int For Loops

Mar 4, 2014

I would like to know which one is more appropriate to use in "for" loops or "while" loops.I don't know exactly when to use Integer or int.

for(int i=0; i<10; i++){ ... }
for(Integer i=0; i<10; i++){...}

View Replies View Related

Not Printing Output When Using While Loops?

May 17, 2015

I am learning while loops but the output I am getting is not what I want? My class:

public class BottlesOnWall {
public static void main (String[] args) {
int x = 99;
while (x > 1) {
System.out.println(x + " bottles on the wall!");

[Code] .....

The output I am getting is this:

99 bottles on the wall!
98 bottles on the wall!
97 bottles on the wall!
96 bottles on the wall!
95 bottles on the wall!

[Code] ....

I want it to stop on "2 bottles on the wall!" and then print "Only 1 bottle left on the wall!". How do I go about doing that? I have tried different variations of the condition (x>1), I have tried (x>5) but it still goes down to 1 bottle?

View Replies View Related

How To Build Triangle Using Loops

Jan 16, 2014

I need to build the triangle like below. How to solve this using loops.

*
* *
* * *
* * * *
* * * * *

View Replies View Related

For Loops Reverse Method

Oct 29, 2014

I'm trying to make a piece of code that writes a for Loop program using OOP. I need to create a class, name that class and have it contain several reverse methods and use a runner class to test it.So far this is the code I've come up with. Does it work or not?

public class loopDemo{
public static void main(string[]args){
String alphabet = "abcdefghijklmnopqrstuvwxyz";
public String reverse(){
char myBoi;
int myIta;
String tebahpla
for(myIta=25j i>=0 ji++){
tebahpla+= alphabet.charAt(myIta);

View Replies View Related

Populate A Database Using Loops

Jan 6, 2014

I am relatively new to Java and I am only beginning to learn about SQL. I have some basic's down but I have been wondering is there a way that I can add data to my database using loops instead of having to physically code every row/column individually ?

View Replies View Related

Loops For Parallel Arrays

Mar 26, 2015

how to loop my arrays, so when I sort them (highest/lowest) the 2nd array corresponds to the sorted array

import java.util.Scanner;
import java.util.Arrays;
public class ArraysArrays {
public static void main (String[] args){

[code]....

View Replies View Related

Using Loops To Do Multiple Divisions

Feb 2, 2015

I am trying to write a program that will take two inputted numbers (a and b) and determine how many divisions can be done by dividing by b until the quotient is less than b. For example if a=64 and b=2, then you would be able to do:

64/2=32
32/2=16
16/2=8
8/2=4
4/2=2
2/2=1

1<2

so there is 6 divisions.

How would I use a loop to create this type of program?

View Replies View Related

Replace Four Loops Through Switch Box?

Sep 11, 2014

I will like replace this code:

// boucle pour les fractions aleatoires
for (i=0; i<2; i++) {

// Creation des fractions aleatoires
Frac first = new Frac(r,5);
Frac second = new Frac(r,5);

[Code] .....

But when I use a switch case I do not have the same result as my four loops.

View Replies View Related

Using Loops For Dice Probability

Oct 5, 2014

The instructions are to "write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled... then ask the user to enter the number of sides on a die" The code is all provided here, I just have to put it in the right spots. (Side note, I cannot use arrays.) Here's the original file I was given to work with:

Java Code:

import java.util.Random;
import java.util.Scanner;
public class DiceProbability
{
public static void main(String[] args) {
//Declare and initialize variables and objects
//Input: ask user for number of rolls and number of sides on a die
//Print heading for output table

[Code] ....

When I run it, I get something like this (just a part of my output):

Please enter the number of sides on a die: 6
Please enter the number of rolls: 2

Sum of dice Probability

20.0
20.0
30.0
30.0
40.0
40.0
50.0
50.0
650.0
650.0
70.0
70.0

Now I don't really understand the concept in the first place as the lesson was extremely uninformative, so I don't know what went wrong here.

View Replies View Related

Nested Patterns Using For Loops

Feb 9, 2015

i want to use nested loops to print patterns but i cant seem to make a pattern that will look like V and K this should be the outcome.

* *
* *
* *
* *
*

@ @
@ @
@@
@ @
@ @

View Replies View Related

Nested Loops Or Set Operations?

Oct 10, 2013

Is there any advantage to using Java's operations defined in sets or collections over inspecting in nested for-loops?

For example, suppose I want to keep items from one array that do not appear in another, I could do:

for( PrimitiveType prim_1 : someArray ){
for( PrimitiveType prim_2 : otherArray ){
if( prim_1 != prim_2){
///put in some return list
}
}
}

Or else I could do:

ArrayList<NotPrimitive> excludedElements =
new ArrayList(Arrays.asList(primitiveArrayToExclude));
for( PrimitiveType elem : someArray){
if( ! excludedElements.contains( elem ) {
//put in some return list
}
}

I personally see no improvement in legibility nor any reduction of error potential.....

View Replies View Related

Nesting Loops - Odd / Even And Zero Digits In Integer Value

Oct 13, 2014

So I am trying to do this program but I can't figure out how to nest it properly. The prompt is :

Design and Implement an application that determines and prints the number of odd,even,and zero digits in an integer value read from the keyboard.

The catch is, strings are not allowed. This is what I have so far :

import java.util.Scanner;
 public class OddEvenZero {
 public static void main(String[] args) {
int zero = 0, even = 0, odd = 0, num, num2;

[Code] ....

View Replies View Related







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