You are on page 1of 66

Scribd

Explore

UploadSaved

207 full
Uploaded by Varun Bhardwaj on Apr 09, 2017

Related Interests
Array Data Structure
Integer (Computer Science)
String (Computer Science)
Parameter (Computer Programming)
Function (Mathematics)

Rating and Stats


20
35 views
5/5 score

Document Actions
Download

Save for Later


Other Actions

SHARE OR EMBED DOCUMENT

Embed
Description: Java Programs practice
View More
Java Programs practice
Copyright: All Rights Reserved
Downloadas TXT, PDF, TXT or read online from Scribd
Flag for inappropriate content

Recommended Documents
Documents Similar To 207 full

HandsOn_3

by Dipak Nandeshwar

Find the Equation

by abhishek

Google Interview Puzzuls

by Vinay Pandey

Documents About Array Data Structure

Analysis & Design Algorithm MCQ'S

by GuruKPO

Cross Eye Jamming

by Gordon Duff

UT Dallas Syllabus for cs1336.002 05s taught by Laurie Thompson


(lthomp)

by UT Dallas Provost's Technology Group

More From Varun Bhardwaj

Core java

by Varun Bhardwaj

207 full.txt

by Varun Bhardwaj

Web Scripting (Unit-5)

by Varun Bhardwaj

You are on page 1of 233


1. Add and
ReverseGiven an
int array and a
number as input,
write a program
to add all the
elements in the
array greater
than the given
number. Finally
reverse the digits
of theobtained
sum and print
it. Include a class
UserMainCode
with a static
method
?addAndReverse
? that accepts
2 arguments and
returns an
integer.The first
argument
corresponds to
the integerarray
and the second
argument
corresponds to
the
number. Create a
class Main
which would get
the required
input and call the
static method
addAndReverse
present in the
UserMainCode.
Example:Input
Array =
{10,15,20,25,30,
100}Number =
15sum = 20 + 25
+ 30 + 100 =
175output =
571 Input and
Output
Format:The first
line of the input
consists of an
integer that
corresponds to
the number of
elements in the
array.The next n
lines of the input
consists of
integers that
correspond to the
elements in the
array.The last
line of the input
consists of an
integer that
corresponds to
the
number. Output
consists of a
single
integer. Sample
Input610152025
3010015 Sample
Output5711.Add
and
Reverse*******
*************
*************
*************
**********
571public class
Main {public
static void
main(String[]
args) {int[]
a={10,15,20,25,
30,100};int
b=15;int
i,sum=0,r=0;for(i
=0;i<a.length;i+
+){if(a[i]>b){su
m=sum+a[i];}}//
System.out.printl
n(sum);while(su
m!=0){r=(r*10)+
(sum%10);
sum=sum/10;}S
ystem.out.println
(r);;}}2..Add
TimeWrite
a program
to read two
String variables
containing
time intervals
in hh:mm:ss
format.Add the
two time
intervals and
return a string in
days:hours:minut
es:seconds
format where
DD is number of
days.Hint:
Maximum value
for hh:mm:ss is
23:59:59Include
a class
UserMainCode
with a static
method addTime
which accepts
the string values.
The return type
is the
string.Create a
Class Main
which would be
used to accept
the two string
values and
call the static
method present
in
UserMainCode.I
nput and Output
Format:Input
consists of two
string.Output
consists of a
string.Refer
sample output
for formatting
specifications.Sa
mple Input
1:12:45:3013:50:
45Sample
Output
1:1:2:36:15Samp
le Input
2:23:59:5923:59:
59Sample
Output
2:1:23:59:58 2.A
dd
Time*********
*************
*************
*************
********public
class Main
{public static
void
main(String[]
args) throws
IOException,
ParseException {
String
s1="23:59:59";St
ring
s2="23:59:59";Si
mpleDateFormat
sdf=new
SimpleDateForm
at("HH:mm:ss");
sdf.setTimeZone
(TimeZone.getTi
meZone("UTC")
);sdf.setTimeZon
e(TimeZone.get
TimeZone("s1"))
;sdf.setTimeZon
e(TimeZone.get
TimeZone("s2"))
;Date
d1=sdf.parse(s1);
Date
d2=sdf.parse(s2);
long
add=d1.getTime(
)+d2.getTime();S
tring
s=sdf.format(add
);Calendar
cal=Calendar.get
Instance();cal.set
Time(sdf.parse(s
));int
FindDay=cal.get
(Calendar.DAY_
OF_MONTH);if
(FindDay>1)Fin
dDay=FindDay-
1;String
op=FindDay+":"
+s;
System.out.printl
n(op);}}3.Adjac
ent SwapsWrite
a Program that
accepts a string
as a parameter
and returns the
string with each
pair of adjacent
letters reversed.
If the string has
an odd number
of letters, the last
letter is
unchanged.Inclu
de a class
UserMainCode
with a static
method
swapPairs which
accepts a string.
The return type
is string which is
reversed pair of
letters.Create a
Class Main
which would be
used to accept
two Input strings
and call the static
method present
in
UserMainCode.I
nput and Output
Format:Input
consists of a
string with
maximum size of
100
characters.Outpu
t consists of a
single
string.Refer
sample output
for formatting
specifications.Sa
mple Input
1:forget Sample
Output
1:ofgrte Sample
Input 2:New
York Sample
Output 2:eN
woYkr *******
*************
*************
*************
***********pu
blic class
Main{public
static void
main(String[]
args) {String
s1="forget";getv
alues(s1);}public
static void
getvalues(String
s1){StringBuffer
sb=new
StringBuffer();
Recommended Documents
Documents Similar To 207 full

HandsOn_3

Find the Equation

Google Interview Puzzuls


Midterm S2 Solutions

1-s2.0-S1570866706001067-main

CS 61C - Fall 2011 - Garcia - Midterm 1

Arrays

L22Arrays1

C Langvage Programs for Practice

questions

Pointer Program

Pointers in C/C++

Pointers Self.rtf

Matlab2016 Sample

CBSE Class 12 Computer Science Sample Paper-04 (for 2013)

CSC108_MidPM_2014W.pdf

i46debsc

Computer Applications ICSE Model Papepr 2016


cplusplus

NPAROMA.ASM

2015_16 - Lecture for RTS Laboratory 2 (1)

2014_HyderabadRegion_PB1

32-Recursive_Select_1pps.pdf

Lesson 4

ASP_C#notes

DS Lab Assignment

(1)Computer Science Project - Copy

Computer Science board paper


FC124

Steganography

Documents About Array Data Structure

Analysis & Design Algorithm MCQ'S

Cross Eye Jamming

UT Dallas Syllabus for cs1336.002 05s taught by Laurie Thompson


(lthomp)

Parallel Networks v. Array Networks

UT Dallas Syllabus for cs1336.002 06s taught by Laurie Thompson


(lthomp)

Algorithms and Data Structure

Algorithm And Programming Language MCQ'S

UT Dallas Syllabus for cs1336.003 06s taught by Shyam Karrah


(skarrah)

UT Dallas Syllabus for cs1336.003 05s taught by George Steinhorst


(csteinh)

Compare "Urdhva Tiryakbhyam Multiplier" and "Hierarchical Array of


Array Multiplier"

tmp244D.tmp

UT Dallas Syllabus for cs1336.005.09f taught by Timothy Farage


(tfarage)

Data Structures and Algorithms MCQ'S

Implementation of Digital Beamforming Technique for Linear Antenna


Arrays

UT Dallas Syllabus for cs1336.001 05f taught by Laurie Thompson


(lthomp)

Nokia VP8 Infringement Claim Chart for '211 Patent

UT Dallas Syllabus for cs1336.002 05f taught by Laurie Thompson


(lthomp)

UT Dallas Syllabus for cs1336.501.10f taught by Timothy Farage


(tfarage)

NIIT Sample Programming Placement Paper Level-1

Data Structure

More From Varun Bhardwaj

Core java

207 full.txt

Web Scripting (Unit-5)


Bank Po preparation tips

unit-1-ppt

Height Distance Cbse Class x Maths 2010

Footer Menu
ABOUT

About Scribd

Press

Our blog

Join our team!

Contact Us

Invite Friends

Gifts

LEGAL

Terms

Privacy

Copyright

SUPPORT

Help / FAQ

Accessibility

Purchase help

AdChoices

Publishers
Social Media

Copyright 2017 Scribd Inc..Browse Books.Mobile Site.Site


Directory.Site Language:
English