• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 72 pages
Exam (elaborations)

Test Bank For Building Java Programs A Back to Basics Approach 5th Edition By Stuart Reges, Marty Stepp (All Chapters, 100 Original Verified, A+ Grade) 3

Document preview thumbnail
Preview 4 out of 72 pages

Test Bank For Building Java Programs A Back to Basics Approach 5th Edition By Stuart Reges, Marty Stepp (All Chapters, 100 Original Verified, A+ Grade) 3

Content preview

1.Write a program to input 2 valid dates, each comprising of day, month and ye
g g g g g g g g g g g g g g


ar and calculate the dates elapsed between two dates
g g g g g g g g




import java.util.*; g




class dates g




{
gggg public static void main(String args[])
g g g g g




gggg {
gggggggg int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
g




gggggggg int d,m,y,d1,m1,y1,s,s1,i,x;
g




gggggggg Scanner br =new Scanner(System.in);
g g g




gggggggg s=0;
gggggggg s1=0;
gggggggg System.out.println("Enter First Date day : "); g g gg g g




gggggggg d=br.nextInt( ); g




gggggggg System.out.println("Enter month : "); g g g




gggggggg m=br.nextInt( ); g




gggggggg System.out.println("Enter year : "); g g g




gggggggg y=br.nextInt( ); g




gggggggg System.out.println("Enter Second Date day : "); g g g g g




gggggggg d1=br.nextInt( ); g




gggggggg System.out.println("Enter month : "); g g g




gggggggg m1=br.nextInt( ); g




gggggggg System.out.println("Enter year : "); g g g




gggggggg y1=br.nextInt( ); g




gggggggg for(i=1;i<m;i++)
gggggggg {
gggggggggggg s=s+a[i];

,gggggggg }
gggggggg if(y%4==0)
gggggggg s=s+1;
gggggggg s=s+d;
gggggggg for(i=0;i<m1;i++)
gggggggg {
gggggggggggg s1=s1+a[i];
gggggggg }
gggggggg if(y1%4==0)
gggggggg s1=s1+1;
gggggggg s1=s1+d1;
gggggggg x=s1-s;
gggggggg System.out.print("Total number of days between : " + d+"/"+m+"/"+y);
g g g g g g g g




gggggggg System.out.print(" and " + d1+"/"+m1+"/"+y1);
g g g g




gggggggg System.out.print(" is " + x); g g g g




gggg }
}

OUTPUT:
Enter First Date day :
g g gg g g



16
Enter month : g g g



10
Enter year : g g g



1952
Enter Second Date day :
g g g g g



24

,Enter month : g g g



12
Enter year : g g g



200
Total number of days between : 16/10/1952 and 24/12/2005 is 68
g g g g g g g g g g




Algorithm:
1. Start
g




2.Input first date ,month and year g g g g g




3.Input second date, month and year g g g g g




4. Start the loop
g g g




gggggggggg s=s+a[i];
gggggggg if(y%4==0) then s=s+1 and s=s+d; g g g g




ggggggggg next loop for(i=0;i<m1;i++)
g g




gggggggggggg s1=s1+a[i];
gggggggg if(y1%4==0) then s1=s1+1; g gg




gggggggg s1=s1+d1;
gggggggg x=s1-s;

5.Display total numbers between 2 dates. g g g g g




6.Stop
2.Input consists of the month number, the day of month and the year. Write a progr
g g g g g gg g g g g g g gg g g


am to calculate and print the corresponding day of the year
g g g g g g g g g g



import java.util.*; g



class January g



{
gggg public static void main(String args[ ])
g g g g g g



gggg {

, gggggggg int a[ ]={31,28,31,30,31,30,31,31,30,31,30,31};
g g



gggggggg int d,m,y,s,i;
g



gggggggg Scanner in=new Scanner (System.in);
g g g



gggggggg s=0;
gggggggg System.out.println("Enter day : "); g g g



gggggggg d=in.nextInt();
gggggggg System.out.println("Enter month : ");g g g



gggggggg m=in.nextInt();
gggggggg System.out.println("Enter year : "); g g g



gggggggg y=in.nextInt();
gggggggg for(i=0;i<m-1;i++)
gggggggg {
gggggggggggg s=s+a[i];
gggggggg }
gggggggg if(y%4==0)
gggggggg s=s+1;
gggggggg s=s+d;
gggggggg System.out.println("Total number of days : " + s);
g g g g g g g




gggg }
}

Output:
Enter day : g g g




5
Enter month : g g g




3
Enter year : g g g




2000

Connected book
 image
Stuart Reges, Martin Stepp Building Java Programs
Publisher: 2014 ISBN: 9780133360905 Edition: Unknown

Document information

Uploaded on
December 15, 2024
Number of pages
72
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$18.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TESTBANKPROF
4.8
(694)
Sold
12
Followers
0
Items
313
Last sold
2 weeks ago


Reviews from verified buyers




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions