Quick question about my output
I am trying to write a project to calculate 5 birthdays. There are no errors and it calclates the first 4 birthdays fine but when i type in the 5 birthday it comes up with the wrong birthday. Or if i enter the same brithday 5 times it come up wrong
here are the bdays i have to enter
1/1/90, 9/25/90, 9/30/90, 10/15/90, 11/1/90
thanks in advance
package cmpproject2;
import chapter2.MyInput;
public class Project2Class
public static void main(String[] args)
{ //declare variables
int year, myyear, month, mymonth, day, myday, age, count, otherbdays;
//prompt user to enter today's year
System.out.println("Please enter today's year: example 2002");
year = MyInput.readInt();
if(year < 1)
System.out.println("invalid year, please enter a positive number");
year = MyInput.readInt();
//prompt user to enter today's month
System.out.println("Please enter today's month example 1-12");
month = MyInput.readInt();
if(month < 1 || month > 12)
System.out.println("invalid month, please enter again(1 to 12)");
month = MyInput.readInt();
//prompt user to enter today's day
System.out.println("Please enter today's day");
day = MyInput.readInt();
if (day < 1 || day > 31)
System.out.println("Please enter again (1 to 31)");
day = MyInput.readInt();
//ask how many birthdays
System.out.println("Enter # of birthdays you wish to calculate");
otherbdays=MyInput.readInt();
count=0;
while(count<otherbdays)//this will loop once for each bday
//prompt user to enter your birthday's year
System.out.println("Please enter your birthday's year example yyyy");
myyear = MyInput.readInt();
if(myyear < 1)
System.out.println("invalid year, please enter a positive number");
myyear = MyInput.readInt();
//prompt user to enter your birthday's month
System.out.println("Please enter your birthday's month");
mymonth = MyInput.readInt();
if(mymonth < 1 || mymonth > 12)
System.out.println("invalid month, please enter again(1 to 12)");
mymonth = MyInput.readInt();
//prompt user to enter your birthday's day
System.out.println("Please enter your birthday's day # 1-31");
myday = MyInput.readInt();
if (myday < 1 || myday > 31)
System.out.println("Please enter again (1 to 31)");
myday = MyInput.readInt();
if (myday > day)
month = month - 1;
if (mymonth > month)
year = year -1;
//calculate the user age
age = year - myyear;
//Display results
System.out.println(" Your age is: " + age);
//get next bday
count++;
System.out.println();
System.out.println("Programmer: Brian Jacoviello");
}//end main method
}//end Project2
I compiled your program and tested it, heres all in and output:
Please enter today's year: example 2002
2002
Please enter today's month example 1-12
10
Please enter today's day
15
Enter # of birthdays you wish to calculate
5
Please enter your birthday's year example yyyy
1990
Please enter your birthday's month
1
Please enter your birthday's day # 1-31
1
Your age is: 12
Please enter your birthday's year example yyyy
1990
Please enter your birthday's month
9
Please enter your birthday's day # 1-31
25
Your age is: 12
Please enter your birthday's year example yyyy
1990
Please enter your birthday's month
9
Please enter your birthday's day # 1-31
30
Your age is: 11
Please enter your birthday's year example yyyy
1990
Please enter your birthday's month
10
Please enter your birthday's day # 1-31
15
Your age is: 10
Please enter your birthday's year example yyyy
1990
Please enter your birthday's month
11
Please enter your birthday's day # 1-31
1
Your age is: 9
Programmer: Brian Jacoviello
So, the error isn't that hard to find. Look at this:
if (myday > day)
month = month - 1;
if (mymonth > month)
year = year -1;You change the current date. Your first birthday is always correct, but what happens if you first type in 9/25/90 and after that 10/15/90?
The first if statement is true, because 25>15 so you decrease the current date by one. The age for the first birthday is correct, but now you type in the second (10/15/90) I can assure you that a guy with this birthday is exactly 12 years old!
But remember, you decreased the month of the current date by 1, so the variable month holds the value 9 (10-1). Now the second if statement is true, and the year of the date is decreased by 1. So your program would show an age of 11.
It's really simple to correct the mistake just concentrate on these lines:
if (myday > day)
month = month - 1;
if (mymonth > month)
year = year -1;If you can't correct it post again, you will get more help.
Similar Messages
-
A quick question about WebDynpro SLD and R/3 with concurrent users
Hello ,
I have a very quick question about Webdynpros and SLD connecting to an R/3 system, when you configure a webdynpro to connect to an R/3 system using SLD, you configure a user name and password from the R/3 for the SLD to use. What I would like to know is when I have concurrent users of my webdynpro, how can I know what one user did in R/3 and what another user did? Is there a way for the users of the web dynpro to use their R/3 credentials so SLD can access the R/3? Like dynamically configuring the SLD for each user?
- I would like to avoid leaving their their passwords open in the code ( configuring two variable to get the users username and password and use these variables as JCO username and password )
Thanks Ubergeeks,
GuyHi Guy
You will have to use Single Sign On to achieve this. In the destination you have defined to connect to R/3 , there is an option to 'useSSO' instead of userid and password. This will ensure that calls to R/3 will be with the userid that has logged into WAS. You wont need to pass any passwords because a login ticket is generated from WAS and passed on to R/3. The userid is derived from this ticket.
For this to happen you will have to maintain a trust relation ship between R/3 and your WAS ,there is detailed documentation of this in help files. Configuration is very straight forward and is easy to perform
Regards
Pran -
Hi, I have a quick question about port forwarding/mapping. My question, lets say I am running MSN messenger, who's ports are 6880-6900. But lets say I am running a torrent application or something else that requires those ports. If both applications were running at the same time, would this cause interference with them on the same ports or now. Thanks
NathanNormally, only one application can listen to a specific port number at a time. If MSN is grabbing those 21 ports then your torrent app won't be able to run.
However, most apps don't work that way - even if they use multiple ports, they don't use them all at the same time, so MSN might use 6880 when it starts up, leaving the others open for other applications to use if needed.
Only experimentation will answer that one. -
Make sure that your bean is implementing the serializable interface and that
you are accessing the bean from the session with the same name.
Bryan
"Sandeep Suri" <[email protected]> wrote in message
news:[email protected]..
Hi, I have quick question about use of USEBEAN tag in SP2. When I
specify a scope of SESSION for the java bean, it does not keep the
values that I set for variable in the bean persistent.Thanks,Sonny
Try our New Web Based Forum at http://softwareforum.sun.com
Includes Access to our Product Knowledge Base! -
CBWFQ: Question about the output of "show policy-map interface" command
Hi everyone,
I have a question about the output of "show policy-map interface" command.
The following is the output of this command and lower side of the output shows
(total queued/total drops/no-buffer drops) 0/342/0
If the packets drop occur due to the situation of no enough buffer,
"no-buffer drops" counted up. But "no-buffer drops" has not been counted up.
The "no-buffer drops" is 0 (zero) but "total drops" are counted as 342.
I guess there are other factors except "no-buffer drops" to add "total drops".
But I can not find any information about "other factors".
So I would like to know the "other factors" added to "total drops".
reserch-3725#sh policy-map interface fastethernet0/1
FastEthernet0/1
Service-policy output: shaping
Class-map: kdpc (match-all)
146956873 packets, 115209221595 bytes
5 minute offered rate 156000 bps, drop rate 0 bps
Match: access-group name YOKOHAMA_to_CHINO
Traffic Shaping
Target/Average Byte Sustain Excess Interval Increment
Rate Limit bits/int bits/int (ms) (bytes)
9360000/9360000 58500 234000 234000 25 29250
Adapt Queue Packets Bytes Packets Bytes Shaping
Active Depth Delayed Delayed Active
- 0 146956724 3539850811 2960247 3851843541 no
Class-map: class-default (match-any)
552458414 packets, 249687580329 bytes
5 minute offered rate 242000 bps, drop rate 0 bps
Match: any
Traffic Shaping
Target/Average Byte Sustain Excess Interval Increment
Rate Limit bits/int bits/int (ms) (bytes)
3072000/3072000 19200 76800 76800 25 9600
Adapt Queue Packets Bytes Packets Bytes Shaping
Active Depth Delayed Delayed Active
- 0 552453209 573909865 30358216 2926188156 no
Service-policy : policy1
Class-map: dlsw (match-all)
979578 packets, 264843255 bytes
5 minute offered rate 0 bps, drop rate 0 bps
Match: access-group name acl-dlsw
Queueing
Output Queue: Conversation 137
Bandwidth 128 (kbps) Max Threshold 64 (packets)
(pkts matched/bytes matched) 20922/17371500
(depth/total drops/no-buffer drops) 0/0/0
Class-map: telnet (match-all)
29938 packets, 1806058 bytes
5 minute offered rate 0 bps, drop rate 0 bps
Match: access-group name acl-telnet
Queueing
Output Queue: Conversation 138
Bandwidth 64 (kbps) Max Threshold 64 (packets)
(pkts matched/bytes matched) 639/38900
(depth/total drops/no-buffer drops) 0/0/0
Class-map: class-default (match-any)
551448911 packets, 249420939729 bytes
5 minute offered rate 242000 bps, drop rate 0 bps
Match: any
Queueing
Flow Based Fair Queueing
Maximum Number of Hashed Queues 128
(total queued/total drops/no-buffer drops) 0/342/0
Your information would be appreciated.Details infomatiuon regarding show policy-map interface
http://www.cisco.com/en/US/tech/tk543/tk545/technologies_tech_note09186a008010dd6a.shtml
http://www.cisco.com/en/US/tech/tk543/tk760/technologies_tech_note09186a0080108e2d.shtml
http://www.cisco.com/univercd/cc/td/doc/product/software/ios123/123cgcr/qos_r/qos_s2g.htm#wp1146884 -
Quick Question about Cisco 3560 and the Web Device Manager
Alright, I have a quick question that I am curious about but I haven't found any information
about it.
When I log into my Cisco 3560 using the web portal to get to the Device Manager. Below the
diagram of the switch, then under the Dashboard there is section called Switch
Health, Port Utilization.
Under the Switch Health there is Bandwidth Used, Packet Error. Those two options just sit
at zero and do not move. The Port tilization graph is also sitting at zero.
Is there a way to make them functional?Anyone notice performance increase or decrease of their HD when using the nVidia IDE SW drivers? particularly with a 74GB Raptor? I've also heard of burner issues when installing the IDE SW but have not used my burner yet.
-
IMovie - quick questions about video files when importing and optimizing
Hi, have some quick questions. I think they are simple.
1. When I import a video (from say iPhoto), where does it get "Move" or "Copy" to?
2. Why would I want to do "Copy" instead of "Move", because isn't it then taking up more space?
3. I'm wondering if after I optimize a video, I can stash away the original (non-optimized video that I either "Move"d or "Copy"d earlier) into an external hd.
4. By the way, what is the new file name of the optimized video?
Though things are working fine in iMovie and iPhoto, I'm trying to manage hard disk space, and hope answers to these questions will help.
Do you guys have a guideline on how to manage hard disk space when it comes to iphoto and imovie?
Thanks.As has been suggested you can encourage people to download QuickTime player by doing something like this...
http://www.mirroroftheuniverse.com/Songs.html
You can also present your songs like this...
http://roddymckay.com/Satellite/JukeBox.html
This is a SnoCap jukebox and you need an account to use it but you'll get the link to ESnips on the above page.
A 3 minute song has a file size of about 30 Mb in AIFF format. Converting it to MP3 reduces it to about 3.5 Mb and M4A to about 5.5 Mb.
iTunes will do these conversions for you and M4A is far superior to MP3 as far as sound quality is concerned. -
Two quick questions about Library after moving beginning on a new computer
Hi there,
I just moved from Windows to Mac, meaning I had to move my iTunes library from the old PC to my new MBA.
Just a couple of quick questions.
1. When I started iTunes on my new Mac, in the preferences I directed the media folder to the folder with all my itunes music/podcasts etc, and then I imported the Library XML file. Is this incorrect? Should I have imported a different file? Should I have used the itl file instead?
If so, should I delete the library and start again? (if this is the case, please suggest the best way of doing this without affecting my media)
- a kind of sub-question to this one: some of the media files arent showing up in the iTunes library, but they are in the media folder on the ext HDD. Is there a way I can find out which ones havent been recognized by iTunes? Whats the best way of getting them in to my library?
2. Pretty much half of my podcasts have not been loaded in the new iTunes. The ones that havent were ones that I subscribed to on my iPhone, whereas the ones that show up in iTunes were ones I downloaded from iTunes. When I connect my iPhone and sync it with iTunes, will those podcasts show up in iTunes? Or is there a risk that they will be deleted from my iPhone?
Cheers,The .xml is lacking some information such as ratings, date added, and play count. Using the .itl includes this information but cannot be imported using the method you did.
A complete library is everything in the iTunes folder. By using the method you did you left the artwork behind in the artwork folder on the other machine.
Selecting the media folder in preferences does not get iTunes to recognize the media. All it does is tell iTunes to start storing new media in that location.
Using the method I outlined nothing will be missed (with the exception of WMA) because you aren't rebuilding your library, you are using the one that already exists.
You don't have to re-copy everything as long as you get the stuff you missed and re-assemble it all as it was before except not on the Mac.
What are the iTunes library files? - http://support.apple.com/kb/HT1660
More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
Where are my iTunes files located? - http://support.apple.com/kb/ht1391 -
Quick question about Quicktime media keys.......
I had a question about encoding video and media keys. It seems to me that the only codec that allows you to encode it with a media key is Sorenson (Sorenson 3 I think). Why are they the only ones that are enabling that in their codecs? Is it kind of a dying technology or practice? I've experimented with Sorenson 3 and Sorenson Squeeze trials and, even though it looks ok, it simply doesn't stack up to others like Apple's H.264 or open-source x264 or even Xvid. I guess I wish there were a way to be able to use media key options with all the new H.264 codecs. Is it possible to do that, either with Xcode or AppleScript? Any help would be greatly appreciated!!
QuickTime has supported 'media keys" since version 3 but you can only add them using the third party software.
You would be better served by contacting Sorenson and asking them about their support for newer codecs. -
Quick Question about fade effect
Quick Question:
If I wanted to add a Fade Effect from one state to another
when a button is pressed.
How would I do that within the code?quote:
Originally posted by:
atta707
You can do something like on the click of the button:
var fader:Fade = new Fade(targetUIComponent);
fader.duration = 1000;
fader...;
fader.play();
or listen for currentStateChanging event and write the same
similar code.
or define transitions from one state to another like:
<mx:Transition id="toOneOnly" fromState="*"
toState="OneOnly">
<mx:Sequence id="t1" targets="{[p2]}">
<mx:Iris showTarget="false" duration="350"/>
<mx:SetPropertyAction name="visible"/>
<mx:SetPropertyAction target="{p2}"
name="includeInLayout"/>
</mx:Sequence>
</mx:Transition>
Hey,
I would like to use the "transition from one state to
another", but if you can explain each part for me that would be
helpful.
If you can comment on each line of that code that would help
thanks -
Quick question about showing drive space
Hi,
Just got a quick query about showing remaining drive space on the desktop.
Before I wiped my Pismo and reinstalled Tiger (bad kernel panic), my hard drive and any other connected drives (pen drive, iPod, iDisk, etc) showed up on my Desktop with the name and drive capacity and remaining space underneath the icon.
Now I've reinstalled, the drive capacity and remaining space don't show up on the Desktop, and I can't find how to turn it on. I've been through Preferences several times and can't find an obvious switch. Have I missed something? I'm running Tiger 10.4.8 with the machine spec below.
Thanks in advance,
Rob JohnsonSometimes, for no obvious reason, the Finder can be slow to update. And sometimes it updates instantly. Why? "Only the Shadow knows...." or maybe the Apple programmers.
Francine
Francine
Schwieder -
Quick question about sim transfer
Hi all,
I have a quick question and hopefully one of you guys would be able to help me. My friend purchased his 3g iphone today and hes giving me his old iphone. I currently have a blackjack and I wanted to take the sims card from the blackjack and put into the original iphone. Will the iphone work with my sims card? It is an older sims card, says 64k on it. If not, would I have to bring it into at&t and get it activated w/a different sims card? Hopefully all this isnt confusing. Thanks for any help. Cheers!You're welcome.
I guess that also means I would have to upgrade to the 20 dollar data plan without the text messages as well?
The unlimited data plan for the first generation iPhone still costs $20/mo and includes 200 SMS. The only thing you need to get from an at&t store is a new SIM card. Take the iPhone with you telling them what you plan on doing and they should give you a new SIM card at no cost.
You will activate this iPhone with iTunes on your computer. If you are an existing subscriber, your calling plan will transfer to the iPhone, and any existing data plan you are using with your current phone will be cancelled. If you are an existing subscriber, your only selection will be the $20/mo unlimited data plan which includes 200 SMS, and you can select 1,500 SMS for an additional $10/mo or have unlimited SMS for an additional $20/mo. -
I have a question about iMovie. I've used Final Cut Pro before using iMovie, and FCP allowed the user to play two video/images on top of each other. You could play with the opacity and the duration very easily.
I'm wondering, can you do the same thing with iMovie? I'll be VERY disappointed if you can't do it.
iBook G4Hi
And You could take a look at the plug-ins to iMovie.
- Stupendous software http://www.stupendous-software.com
- GeeThree http://www.geethree.com
- cf/x. http://www.imovieplugins.com
and possibly more.
QT-pro can do this as said above - but You need to be very precise.
But I would do this in FCP and then export as QT.mov to do the rest in iMovie
if necessary.
Yours Bengt W -
Just a quick question.
In other languages, I can do this...
while(reg.exec(string)) {
//loop through results
And while looping, I can access the current match with something like reg.Match or whatever.
Is this possible in AS?Look up the RegExp class.
-
Hi,
Very quick question,
Are the newer SATA2 Hard Disks compatible with the older model of the Mac Pro? May sound stupid, but I believe that the Mac Pro was released before the SATA 2, so just wanted to check the Mac Pro hardware etc will take SATA 2.
By older model of Mac Pro, I mean the one released before the newest available models (2 x 2.66Ghz Dual Core).
Thanks!Hi 02drummersteve02;
SATA 2 is backwards compatible with SATA 1. So you can install SATA 2 drives in a SATA 1 computer.
Allan
Maybe you are looking for
-
Hi All, I have a doubt related to mid-year go-live... Is it necessary to do mid year go live activity (for India payroll) or can we go live without mid year activity? Regards, Prasad Lad
-
How to Remove contents of Recently Viewed List?
Is there any possibility of removing the contents of recently viewed list from the action bar as well as at the home page layout?. For Example, I first have an account which is assigned to "Agent 1" and later reassigned to "Agent 2". if Agent 1 was h
-
Storage Type 916 in the outbound delivery
SAP GURU, When i am creating a outbound delivery against a sales order...as my Plant is warehouse mnamanged so Warehouse will automatically get determined in the delivery based on SPRO setting but i am not able to find out how storage type 916 at the
-
my disk drive will start up when i plug it in, and runs for about 30 seconds, but wont get recognized in my computer. It used to show up in the finder but that doesnt happen anymore
-
Assign Plan/Budget profile to Internal Order
While executing KO22 for particular internal order for order type 0800, I am getting the error - Assign Plan/Budget profile to the object. GMR