Need help with a For loop that uses a Break statement
I need to create a for loop which counts down from 100-50 and divides the number being counted down by a counter. Can anyone help me?
public class Break
public static void main ( String args []) (;
int total = 0
int counter = 0
for { (int number = 100; total >=50; total --)
if (counter == 0)
break;
} // end of for loop
int output = number/counter
system.out.printf("The number is" %d output/n)
}// end of method main
}// end of class Break
Im sorry I didnt explain myself very well i do not need the break statement at all.
I now have this code:
public class BreakTest
public static void main( String args[] )
int count; // control variable also used after loop terminates
for (int i = 100; i >= 50; i = ++count)
if (i >= 50) {
continue;
System.out.printf( "\nBroke out of loop at count = %d\n", count );
} // end main
} // end class BreakTest
/code]
and i get these error messages:
F:\csc148>javac BreakTest.java
BreakTest.java:9: variable count might not have been initialized
for (int i = 100; i >= 50; i = ++count)
^
BreakTest.java:15: variable count might not have been initialized
System.out.printf( "\nBroke out of loop at count = %d\n", count );
^
2 errors
Similar Messages
-
Need help with basic "for" loops!
Here is my prompt for class:
Write a program that prompts the user to enter a sentence from the keyboard using JOptionPane.showInputDialog.
The program will print the characters back with the first letter of each word changed from lower case into upper case. If you have a capital letter in the original line and it is not the first letter of a word, then this letter should be switched from upper case to lower case. The only capital letters that should appear in the line must be the beginning letter of every word in the line. All other characters will remain the same.
I figured everything out except for one part. How do I make the first letter of each word change from lower case into uppercase? How do I switch a letter that is uppercase in the middle of a word to lowercase? Last but not least, how do I make sure that the only capital letters in the sentence are the first letter of each word?
I need to do this using for Loops, charAt(), and if/else statements because this is just an intro class. I just can't figure this last part out! Help please!String words = ...;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < words.length; i++) {
char c = words.charAt(i);
boolean isUpper = Character.?(look up the methods in java.lang.Character)
boolean isLetter = ? (there are actually 2 ways to do this. Hint: you can use <= and >= and && to solve this)
if (!isLetter) {
continue;
} else {
// check if this is the start of the word. How do you know that you are at the start of a word?
if (!isUpper && isStartOfTheWord) c = Character.toUpperCase(c); //Hint: there is a way you can do this with x + y
else if (isUpper) //make c lower case
builder.append(c);
return builder.toString(); -
I need help with my for loop in this array
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
import javax.swing.JOptionPane;
public class Runner
public static void main (String[] args)
String timeStr;
int time, again, optiStr;
Inbound[] in = new Inbound[25];
in[0]=new Inbound ("",0,"On Time num0");
in[1]=new Inbound ("",2,"On Time num1");
in[2]=new Inbound ("",3,"Delayed num2");
in[3]=new Inbound ("",4,"On Time");
in[4]=new Inbound ("",5,"On Time");
in[5]=new Inbound ("",6,"Canceled");
in[6]=new Inbound ("",1,"Canceled num6");
in[7]=new Inbound ("",8,"On Time");
in[8]=new Inbound ("",9,"Delayed");
in[9]=new Inbound ("",10,"On Time");
in[10]=new Inbound ("",11,"Delayed");
in[11]=new Inbound ("",12,"On Time");
in[12]=new Inbound ("",13,"Delayed");
in[13]=new Inbound ("",14,"On Time");
in[14]=new Inbound ("",15,"On Time");
in[15]=new Inbound ("",16,"On Time");
in[16]=new Inbound ("",17,"Canceled");
in[17]=new Inbound ("",18,"On Time");
in[18]=new Inbound ("",19,"On Time");
in[19]=new Inbound ("",20,"Canceled");
in[20]=new Inbound ("",21,"On Time");
in[21]=new Inbound ("",22,"Delayed");
in[22]=new Inbound ("",23,"On Time");
in[23]=new Inbound ("",24,"Cancled");
in[24]=new Inbound ("",7,"On Time num24");
do{
timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
time = Integer.parseInt(timeStr);
if (time<=0 || time>24)
JOptionPane.showMessageDialog (null, "Error");
optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
if (optiStr==JOptionPane.YES_OPTION)
//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
// else JOptionPane.showMessageDialog (null, "else");
}//temp return else if failed to find time asked for
// else
// if (optiStr==JOptionPane.CANCEL_OPTION)
// JOptionPane.showMessageDialog(null,"Canceled");
// else
// {Outbound.run();
// JOptionPane.showMessageDialog (null, "outbound");}//temp
again=JOptionPane.showConfirmDialog(null, "Try again?");
while (again==JOptionPane.YES_OPTION);
}any help would be greatly appriciated.rumble14 wrote:
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
>//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
Edited by: darb on Mar 26, 2008 11:12 AM -
Hello,
I hope someone can point me in the right direction for my next assignment. I am very new at Java programming. For my next assignment for class I will need expand my previous program which was a mortgage calculator. The first assignment we wrote a program to show the monthly payments of a $200,000 loan at 5.75% for 30 years. Now we have to output all 360 monthly payments with pauses in between so it doesnt scoll off the page. The calculation that we use is:
month_payments = (principle * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));
My question is how do I get the correct calculation outputed 360 times. I would like to use the "for loop" to do this. Also what is the correct way to do the pause command? I do not want someone to write the code, I just want some help to where I need to start off, I want to learn this on my own.
Thanks in advance,
DCfor (int i ; i < 10 ; i ++ ) { System.out.println("Come sail away"); }
or;
int i = 0;
while(i < 10)
i++;
System.out.println("Come sail away");
} -
Hi all
I have a dir that has a list of folders that are created using php that my customers upload to. the PHP creates a new folder using the system date on the days that they upload. (using this format yyyymmdd)
What I am trying to do is loop thou the folders and get todays folder and list the files that are in todays folder. I have been able to do this up to the point of if a customer folder does not have a folder called todays date.
I know I need some sort of try / catch but don't know what.
Can anyone help me please
Thanks for you time and help in advance
Craig
public void getfolderList() {
File dir = new File("/Users/craig/Documents/jBuilder_Epod/copy");
File[] getFolderNames = dir.listFiles();
if (getFolderNames != null) {
for (int gf = 0; gf < getFolderNames.length; gf++) {
String store = "" + getFolderNames[gf];
if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
String folderName = "" + getFolderNames[gf];
if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
//I need to have some sort of try and Catch here.
// If there is no Folder called "todaysFileName" I need to go to the next folder
//i.e. stop the for loop and go to next
String setTodaysFileName = folderName + "/";
String todaysFileName = setTodaysFileName + systemDate;
File todaysFolder = new File(todaysFileName);
File[] todaysFiles = todaysFolder.listFiles();
for (int td = 0; td < todaysFiles.length; td++) {
todaysFileName = "" + todaysFiles[td];
System.out.println("There is no folder Today........" +
todaysFileName);
}A quick guess would be that after the sStatement
File[] todaysFiles = todaysFolder.listFiles();todaysFiles is null if todaysFolder doesn't exist and you get a NullPointerException when trying to access todaysFiles.length in the following for-loop.
If that doesn't help, please be a bit more precise what kind of Exception occurs... -
Need help with a for loop - string checking
I am trying to create a for loop to make sure a user entered string contains only letters but something doesn't take. No errors, but the inner loop of try again doesn't ever come into play. What am I missing please.
String k = keyboard.nextLine();
for (int i = 0; i < k.length(); i++)
char c = k.charAt(i);
int m = c;
if (((m < 97) && (m > 122)) || ((m < 65) && (m > 90)))
System.out.print("Try again please: ");
k = keyboard.nextLine();
System.out.println(k);molested,
(you and BigDaddyLoveHandles should get on well)
I would use regular expression for that... which would look something like this...
// get response containing at least one letter.
while (true) {
String response = keyboard.nextLine();
if( response.matches("[a-zA-Z]+") ) break;
System.out.print("Try again please: ");
}Message was edited by: corlettk - frog got the { -
Need help with a for loop please
Hello,
I want to do the following:
double V[][] = sphere.V2;
double polygon[][][] = {
{ V[0], V[1], V[2] },
{ V[1], V[2], V[3] },
{ V[2], V[3], V[4] },
{ V[3], V[4], V[5] },
{ V[4], V[5], V[6] },
{ V[124], V[125], V[126] },
How can I set up a loop to initialize the values of polygon so that I dont have to type it all out?
Thanx a lot
-Big_GoonAny suggestions?
-Big_Goon -
I need help with a PDF file that is an image, the "Read Out Loud' option does not work, please help!
You mean an image such as a scanned document?
If that is the case, the file doesn't contain any text for Reader Out Loud to read. In order to fix that, you would need an application such as Adobe Acrobat that does Optical Character Recognition to convert the images to actual text.
You can also try to export the file as a Word document or something else using ExportPDF which I believe offers OCR and is cheaper than Acrobat. -
Help with a FOR loop and an object array
I need to make a for loop that takes an array of objects that contain the parameters year, type, and model (all ints) and sort by year, then divide the array in all the objects with the same year and sort them by type, then divide the array again into the objects with the same year AND type and sort them by model.
the object a Dress objects, the get methods are get+nameof parameter.
the array is a 1D array called Dresses.
I have made a paralell array to store the value of the parameters and sort that then move the array acording to that sorted array. The problem is in the division of the array.We'll give your request to do (or finish) your homework for you the attention it deserves.
-
on Windows 7, CS6 all products, but especially need help with ID. Fonts that are showing in other applications are not showing in ID.
The ID Program folder will be relevant to your OS...
I took a shot and right clicked on my Scripts Samples, choose reveal in Explorer and opened up the ID Program folder.
As shown, there is a Fonts folder.
Drag/Copy/Paste fonts to this folder. -
Hi guys, been reading your forums, blogposts, etc and am getting more confused. I'm just a video girl trying to produce meaningful content through web videos for small to mid sized businesses and want to come over from the dark side.
Good news,, I dont need a super giant system, I do simple editing for web videos, minimal graphics, no motion graphics, no animation etc. currently using CS4, will probably end up with 5.5.
I want to get imac 21.5 or 27 if i have to.. So here's the question we all have,,, what do I really need besides an Apple fairy godmother to figure this crazy stuff out?????
I want to be able to have firewire add on, but the rest is what I need help with. So i've been looking at cs6 specs, even though im not there yet, eventually will be,, so just need to run cs4 now and build from there. I also want to eventually move to final cut down the road so I want imac able to upgrade to final cut.
WHAT DO I REALLY NEED MINIMALLY FOR NOW? WHAT CAN I GET LATER IF i CHOOSE TO DO MORE AND NEED MORE POWER?
cs6:
Multicore Intel processor with 64-bit support
Mac OS X v10.6.8, v10.7, or v10.8**
4GB of RAM (8GB recommended)
4GB of available hard-disk space for installation; additional free space required during installation (cannot install on a volume that uses a case-sensitive file system or on removable flash storage devices)
Additional disk space required for preview files and other working files (10GB recommended)
1280x900 display
7200 RPM hard drive (multiple fast disk drives, preferably RAID 0 configured, recommended)
OpenGL 2.0–capable system
DVD-ROM drive compatible with dual-layer DVDs (SuperDrive for burning DVDs; Blu-ray burner for creating Blu-ray Disc media)
QuickTime 7.6.6 software required for QuickTime features
Optional: Adobe-certified GPU card for GPU-accelerated performance
Any responses would be great. I know you guys are busy answering the really high end tech questionsAll the current iMac models (both 21.5" and 27" with OS X Mt. Lion 10.8) will run CS4, 5.5 and 6 just fine. They will also run Final Cut Pro X just fine. Ditto for most any application you may want to use.
Below are some notes (specific to your apparent requirements) that may help you with your purchase decision:
Notes on purchasing a 21.5" iMac
All 21.5" iMacs come with 8GB RAM but you cannot add more later. I strongly suggest getting the maximum RAM (16GB) when you order the iMac.
The basic hard drive is a 1TB 5400rpm drive. It will work fine with Adobe CS but you will probably want the added speed of the optional 1TB Fusion drive for better performance. Some people will recommend/argue for one of the optional SSD drives instead, but they are very expensive and still only come in relatively small capacities - I don't recommend the SSD drives. Get the Fusion drive and spend any extra money on a good external hard drive for backup and/or extra storage instead of an SSD.
Notes on purchasing a 27" iMac
All 27" iMacs come with 8GB RAM and you can add more later, up to 32GB
The basic hard drive is a 1TB 7200rpm drive - it will be fine with Adobe CS. There are upgrade options to a 3TB 7200rpm drive or a 1TB or 3TB fusion drive - these will be fine also. There are also SSD drive options, but I do not recommend them. (Same comments as above.)
Notes on all the current iMacs
iMacs no longer come with built-in CD/DVD drives. If you need one, you will need to purchase the Apple Superdrive accessory drive ($79)
All of the iMac graphic processors (GPU's) are compatible with Adobe CS 4, 5.5, 6
It is very difficult to impossible to change or upgrade the hard drive later on, so don't buy low-end thinking you can add a better internal hard drive later.
Be aware that Macs always come with the latest (most recent) version of OS X. And OS X Mavericks (10.9) is due to be released soon (in the next month or two). There is no guarantee that the older Adobe CS 4 or 5.5 versions will run on OS X Mavericks. If you cannot upgrade to CS 6 in the near future, you may want to purchase now rather than after OS X Mavericks is released.
For what it's worth, I'd recommend the 27" iMac if your budget can afford it. You will appreciate the larger screen size and added capabilities over the years you will use the computer. -
Need Help With Download For Airport Express
Ok, computer dummy here needing help with airport express. We were given airport express last night from a friend who recently purchased a newer gadget. He told us we would need to come here to download the operating system. I see lots of links to updates but no links for someone like me who has never had anything like this on my computer before. Does anyone know what link I would need to use? We have a pc with windows XP. Thanks so much for your help!
Hello jesschambers. Welcome to the Apple Discussions!
The AirPort Express Base Station (AX) doesn't have an "operating system" per se, but it does have built-in firmware which pretty much is the same thing. In addition, in order to administer the AX, you will need the AirPort Admin Utility for your Windows PC.
Here are the links for the latest versions of both:
o AirPort Express Firmware Update 6.3 for Windows
o AirPort 4.2 for Windows -
Need help with pagination for book
I am working on a book and need help with the pagination. I was able to make the TOC and front matter show the numbers as Roman numerals, and the body of the text as Arabic numerals, but I can't figure out how to restart the numbering sequence for the body of the text. So the front matter is numbered i-xvi, and the text is 17-681. I need the text to start with the number 1. Each subsequent chapter is a section break as well, if that makes a difference.
Many thanks,
JClick on the page that shall start on number one. Open Inspector palette > Layout inspector (2nd tab) >
Section > Start at: > 1 -
Need help with coding for HTML5 Video with Flash fallback
Hello, need help with my coding in Dreamweaver CS5.5 for HTML5 video with Flash fallback. Not sure if the coding is correct. Do I need anything else Javascipt etc?
The reason you see a blank page is because it's trying to load the file that is pretty humungous and there is no preloader. So, you see a white screen till it complets loading.
Also, the reason why its loading a SWF file and not any of HTML5 type video is because your doctype declaration is XHTML1.0 and not HTML5.
Change the 1st line in your .html file from:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
to:
<!DOCTYPE html>
Then see if your HTML5 video types load with <video> tag. -
Need help with as3 for popup window
I am nearing the end of the semester in my Flash Animation class. I have learned very simple AS3 things, code snippets etc. I am trying to find the actionscript for coding a very simple popup window, but have not found a clue.
Here's what I want to do...I have a white box with some type on the stage. When a person clicks on the white box, I want a popup to open that is larger, that will contain the same type but larger. That box will have an x so it can be dismissed. I don't want to do this in html, only in Flash CS5. I don't want a browser window, I just want a bigger version of the smaller box. I know how to build both boxes, just don't know how to write the code. I know there will be an on-click mouse event listener, and then I am lost.
Can anyone help with the code I might use? It would be most appreciated.It would be something along the lines of... (using instance names relative to your description)...
popup.visible = false;
whiteBox.addEventListener(MouseEvent.CLICK, showPopup);
function showPopup(evt:MouseEvent):void {
popup.visible = true;
popup.popupX.addEventListener(MouseEvent.CLICK, hidePopup);
function hidePopup(evt:MouseEvent):void {
popup.visible = false;
Maybe you are looking for
-
I am a high school teacher. My district purchased the entire CC Suite. Where can I find a tutorial in book form to learn how to use your products? Do you all provide free book samples to teachers?
-
After Effects CC not booting correctly.
My After Effects is taking more than 4 minutes to load and when it does appears to have some errors and not function correctly, taking a long time to do anything and RAM preview only lasting about 10 frames. I am running a Macbook Pro 13" Retina Disp
-
Hi, I'm using a cRIO 9076, LabVIEW 2010 sp1, LabVIEW RT 2010 sp1, LabVIEW FPGA 2010 sp1, NI-RIO 4.0, Xilinx Compile Tools 11.5. Everytime I try to compile code I have a compilation error that read as follows (The same error come up if I try compiling
-
BSP gen in Vivado - failing to execute Tcl commands.
Hi All, Likely a noob question here. Using distro 2014.4. I am trying to run individual tcl commands as per UG1138: Generating basic software platforms, in order to generate a BSP with advance settings. More specifically, I refer to the Appendix C of
-
Mixed periodicities in a forecast are not allowed ???
Hi All, When I try to run the forecast in DP in BACKGROUND then I see following message "mixed periodicities in a forecast are not allowed", but when I execute the forecast in foreground it works completely fine with that forecast profile and everyth