0% found this document useful (0 votes)
391 views

Common Programs For Interviews Java Programs Interview Questions and Answers Paper 356 - Skillgun

Uploaded by

Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
391 views

Common Programs For Interviews Java Programs Interview Questions and Answers Paper 356 - Skillgun

Uploaded by

Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

SKILLGUN
Tes t & I m pr ove you r s ki l l s

(/Home.aspx)
Firsttimeuser?Register(/RegisterUser.aspx)|SignIn(/Login.aspx)

Selectchapter

CommonProgramsforInterviews
All(2.Papers)(http://skillgun.com/commonprogramsforinterviews/interviewquestionsandanswers)
Javaprograms(2.Pape rs)(ht t p://skillgun.com/commonprogramsforint e rvie ws/java
programs/int e rvie wque st ionsandanswe rs)

Fresherint erviewquest ions

Experiencedint erviewquest ions ?

SponsoredLinks
Home(http://skillgun.com/home.aspx)>Technical(http://skillgun.com/technical/interviewquestionsand
answers)>CommonProgramsforInterviews(http://skillgun.com/commonprogramsforinterviews/interview
questionsandanswers)>Javaprograms(http://skillgun.com/commonprogramsforinterviews/java
programs/interviewquestionsandanswers)>Paper1
Readmorepapers: 1(http://skillgun.com/commonprogramsforinterviews/javaprograms/interviewquestionsand
answers/paper/356) 2(http://skillgun.com/commonprogramsforinterviews/javaprograms/interviewquestions
andanswers/paper/357)
(http://skillgun.com/commonprogramsforinterviews/javaprograms/online
test/paper/356)
1.ShowQuestionsonly

? 1.Important

? Submit aQuest ion

(/Submit Quest ions.aspx) Submit Paper(/Submit Paper.aspx)

0SaysImportant
0PeopleLikeit
RateToughness

Reverseelementsofanarray:
Writeaprogramtogeneraterandomnumbersandstoreitintointegerarray.Afterthatreverse
alltheelementswithinthesamearray.
Foreg:ifarrayelementsare{1,2,3,4,5}.Afterreversingarrayshouldlooklike{5,4,3,2,1}.

(http://skillgun.com/question/5564/commonprogramsforinterviews/javaprograms/reverseelementsofanarray
writeaprogramtogeneraterandomnumbersandstoreitintointegerarrayafterthatreversealltheelements
withinthesamearrayforegifarrayelementsare12345afterreversingarrays)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

1/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassArrayReverse{

publicstaticvoidmain(String[]args){
int[]arr=newint[4]
for(intk=0k<arr.lengthk++){
arr[k]=(int)(Math.random()*100)
System.out.println(arr[k])
}
System.out.print("")
System.out.println()
for(inti=0i<arr.length/2i++){
inttemp=arr[i]
arr[i]=arr[arr.length1i]
arr[arr.length1i]=temp
}
for(intj=0j<arr.lengthj++){
System.out.println(arr[j])
}
}
}

Close Answe r

Shareiton

Twitter

Answe r:
De script ion:
0Comme nt s

StartDiscussion(http://skillgun.com/question/5564/commonprogramsfor
interviews/javaprograms/reverseelementsofanarraywriteaprogramtogenerate
randomnumbersandstoreitintointegerarrayafterthatreversealltheelementswith
inthesamearrayforegifarrayelementsare12345afterreversingarrays)

T e llus
Submitnewquestion (http://skillgun.com/SubmitQuestions.aspx)
Questioniswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Question=true&q_id=5564&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
Answeriswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Answer=true&q_id=5564&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
Explanationiswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
explanation=true&q_id=5564&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

2/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

0SaysImportant
0PeopleLikeit
RateToughness

2 Writeaprogramtofindthecommonelementsbetweentwogivenarrays.
(http://skillgun.com/question/5565/commonprogramsforinterviews/javaprograms/writeaprogramtofindthe
commonelementsbetweentwogivenarrays)
Toughness

A. publicclassCommonElementsInArray{

publicstaticvoidmain(Stringa[]){
int[]arr1={4,7,3,9,2}
int[]arr2={3,2,12,9,40,32,4}
for(inti=0i<arr1.lengthi++){
for(intj=0j<arr2.lengthj++){
if(arr1[i]==arr2[j]){
System.out.println(arr1[i])
}
}
}
}
}

Close Answe r

Shareiton

Twitter

Answe r:
De script ion:
1 Comme nt s

StartDiscussion(http://skillgun.com/question/5565/commonprogramsfor
interviews/javaprograms/writeaprogramtofindthecommonelementsbetweentwo
givenarrays)

T e llus
Submitnewquestion (http://skillgun.com/SubmitQuestions.aspx)
Questioniswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Question=true&q_id=5565&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

3 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

Answeriswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Answer=true&q_id=5565&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
Explanationiswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
explanation=true&q_id=5565&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)

0SaysImportant
0PeopleLikeit
RateToughness

3 ReturntheStringbetweenthebraces:

eg:Stringstr1=abc(xyz)ijk
Writethelogictoreturnthestringbetweenthebraces.
(http://skillgun.com/question/5566/commonprogramsforinterviews/javaprograms/returnthestringbetweenthe
bracesegstringstr1abcxyzijkwritethelogictoreturnthestringbetweenthebraces)
Toughness

A. publicclassMain{

publicstaticvoidmain(String[]args){

Stringstr="abiffff(jkllllllllK)l"

inti=str.indexOf("(")

intj=str.indexOf(")")

str=str.substring(++i,j)

System.out.println(str)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

Reverseastring:
Writeaprogramtoreverseastringwithoutusingbuiltinstringfunctions.

(http://skillgun.com/question/5567/commonprogramsforinterviews/javaprograms/reverseastringwritea
programtoreverseastringwithoutusingbuiltinstringfunctions)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

4/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassReverseString{

publicstaticvoidmain()

Stringoriginal,reverse=""

Scannerin=newScanner(System.in)

System.out.println("Enterastringtoreverse")

original=in.nextLine()

intlength=original.length()

for(inti=(length1)i>=0i)

System.out.println("ReversedString

reverse=reverse+original.charAt(i)

is="+reverse)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

5 Stringtolowercase:

WriteaprogramtoconvertthecharacterarraytoLowerCaseandprintit?
(http://skillgun.com/question/5568/commonprogramsforinterviews/javaprograms/stringtolowercasewritea
programtoconvertthecharacterarraytolowercaseandprintit)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

5 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassAsciiValue{

publicstaticvoidmain(String[]args){

charch[]={'P','A','l','L','e'}

intlength=ch.length

for(inti=0i<lengthi++)

intj=ch[i]

if(j<=91&&j>=65)

j=j+32

ch[i]=(char)j

System.out.println(ch)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

6 Removewhitespacesinastring:

Writeaprogramtoremoveallthewhitespacesinagivestring?
Supposeifstr=abcdmvvvthenoutputshouldbeabcdmvvv
(http://skillgun.com/question/5569/commonprogramsforinterviews/javaprograms/removewhitespacesina
stringwriteaprogramtoremoveallthewhitespacesinagivestringsupposeifstrabcdmvvvthenoutput
shouldbeabcdmvvv)
Toughness

A. publicclassRemoveSpaces{

publicstaticvoidmain(String[]args){

Stringstr="a.bcdvvvv"

str=str.replaceAll("","")

System.out.println(str)

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

6/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

7 Writeaprogramtofindthecommoncharactersbetweentwostrings.
(http://skillgun.com/question/5570/commonprogramsforinterviews/javaprograms/writeaprogramtofindthe
commoncharactersbetweentwostrings)
Toughness

A. publicclassStringCompare{

publicstaticvoidmain(String[]args){

Stringstr1="abcdgggg"

Stringstr2="aaabgg"

Set<String>set=newHashSet<String>()

for(inti=0i<str1.length()i++)

for(intj=0j<str2.length()j++)

if(str1.charAt(i)==str2.charAt(j))

set.add(str1.charAt(i)+"")

System.out.println(set)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

7/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

Evenoroddprogram:
Writeaprogramtocheckifanumberisevenorodd?

(http://skillgun.com/question/5571/commonprogramsforinterviews/javaprograms/evenoroddprogramwritea
programtocheckifanumberisevenorodd)
Toughness

A. publicclassCheckEvenOdd{

publicstaticvoidmain(String[]args){

System.out.println("Enterthenumberwhichyou

wanttocheck")

Scannerscan=newScanner(System.in)

intnum=Integer.parseInt(scan.next())

if(num%2==0)

else

System.out.println("Numberiseven:

+num)
System.out.println("Numberisodd:

+num)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

Primenumberprogram:
Writeaprogramtofindoutifanumberisprimenumberornot?

(http://skillgun.com/question/5572/commonprogramsforinterviews/javaprograms/primenumberprogramwritea
programtofindoutifanumberisprimenumberornot)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

8 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. classCheckPrime

publicstaticvoidmain(Stringargs[])

intn,i

Booleanb=false

Scannerscan=newScanner(System.in)

System.out.println("PleaseEnteraNo.")

n=scan.nextInt()

for(i=2i<=n/2i++)

if(n%i==0)

b=true

break

if(n==0||n==1)

else

if(b==false)

System.out.println(n+"isnotaprime

no")

System.out.println(n+"isa

primeno")

else

System.out.println(n+"isanot

primeno")

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

9/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 0 Palindromeprogram:

Writeaprogramtocheckifanumberispalindrome?
(http://skillgun.com/question/5573/commonprogramsforinterviews/javaprograms/palindromeprogramwritea
programtocheckifanumberispalindrome)
Toughness

A. publicclassTest{

publicstaticvoidmain(String[]args){

System.out.println("PleaseEnteranumber:")

intoriginal=newScanner(System.in).nextInt()

intduplicate=original

intreverse=0

while(original!=0){

intremainder=original%10

reverse=reverse*10+remainder

original=original/10

if(duplicate==reverse){

System.out.println(duplicate+is

palindrome)

else{

System.out.println(duplicate+isnot

palindrome)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

10/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

RateToughness

1 1 Fibonacciseries:

WriteaprogramtoprintFibonacciseriesuptogivennumber?
(http://skillgun.com/question/5574/commonprogramsforinterviews/javaprograms/fibonacciserieswritea
programtoprintfibonacciseriesuptogivennumber)
Toughness

A. publicclassFibonacci{

publicstaticvoidmain(String[]args){

intno=0

Scannerscan=newScanner(System.in)

System.out.println("PleaseEnteraNo.")

no=scan.nextInt()

intfib[]=newint[no]

fib[0]=0

fib[1]=1

for(inti=2i<noi++)

for(intindex:fib)

fib[i]=fib[i1]+fib[i2]

System.out.print(index+"")

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 2 Factorialprogram:

Writeaprogramtocalculatefactorialofanintegernumber?
(http://skillgun.com/question/5575/commonprogramsforinterviews/javaprograms/factorialprogramwritea
programtocalculatefactorialofanintegernumber)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

11/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassFactorial{

publicstaticvoidmain(String[]args){

intno,fact=1

Scannerscan=newScanner(System.in)

System.out.println("PleaseEnteraNo.")

no=scan.nextInt()

for(inti=1i<=noi++)

System.out.println(fact)

fact=fact*i

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 3 Selectionsortprogram:

Writethelogictoimplementselectionsort?
(http://skillgun.com/question/5576/commonprogramsforinterviews/javaprograms/selectionsortprogramwrite
thelogictoimplementselectionsort)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

12/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassMySelectionSort{

publicstaticint[]doSelectionSort(int[]arr){

for(inti=0i<arr.length1i++)

intindex=i

for(intj=i+1j<arr.lengthj++)

if(arr[j]<arr[index])

intsmallerNumber=arr[index]

arr[index]=arr[i]

arr[i]=smallerNumber

returnarr

publicstaticvoidmain(Stringa[]){

int[]arr1={10,34,2,56,7,67,88,42}

int[]arr2=doSelectionSort(arr1)

for(inti:arr2){

System.out.print(i)

System.out.print(",")

index=j

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 4 Insertionsortprogram:

Writethelogictoimplementinsertionsort?
(http://skillgun.com/question/5577/commonprogramsforinterviews/javaprograms/insertionsortprogramwritethe
logictoimplementinsertionsort)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

13 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassMyInsertionSort{

publicstaticvoidmain(Stringa[]){

int[]arr1={10,34,2,56,7,67,88,42}

int[]arr2=doInsertionSort(arr1)

for(inti:arr2){

System.out.print(i)

System.out.print(",")

publicstaticint[]doInsertionSort(int[]input){

inttemp

for(inti=1i<input.lengthi++){

for(intj=ij>0j){

if(input[j]<input[j1]){

temp=input[j]

input[j]=input[j1]

input[j1]=temp

returninput

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 5 Mergesortprogram:

Writethelogictoimplementmergesort?
(http://skillgun.com/question/5578/commonprogramsforinterviews/javaprograms/mergesortprogramwritethe
logictoimplementmergesort)
Toughness

A. publicclassMyMergeSort{
h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

14/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

privateint[]array

privateint[]tempMergArr

privateintlength

publicstaticvoidmain(Stringa[]){

int[]inputArr={45,23,11,89,77,98,4,28,65,43}

MyMergeSortmms=newMyMergeSort()

mms.sort(inputArr)

for(inti:inputArr){

System.out.print(i)

System.out.print("")

publicvoidsort(intinputArr[]){

this.array=inputArr

this.length=inputArr.length

this.tempMergArr=newint[length]

doMergeSort(0,length1)

privatevoiddoMergeSort(intlowerIndex,inthigherIndex)

if(lowerIndex<higherIndex){

intmiddle=lowerIndex+(higherIndex

lowerIndex)/2

//Belowstepsortstheleftsideofthe

doMergeSort(lowerIndex,middle)

//Belowstepsortstherightsideofthe

doMergeSort(middle+1,higherIndex)

//Nowmergebothsides

mergeParts(lowerIndex,middle,

array

array

higherIndex)

privatevoidmergeParts(intlowerIndex,intmiddle,int

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

15 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

higherIndex){

for(inti=lowerIndexi<=higherIndexi++)

inti=lowerIndex

intj=middle+1

intk=lowerIndex

while(i<=middle&&j<=higherIndex){

if(tempMergArr[i]<=tempMergArr[j]){

array[k]=tempMergArr[i]

i++

}else{

array[k]=tempMergArr[j]

j++

k++

while(i<=middle){

array[k]=tempMergArr[i]

k++

i++

{
tempMergArr[i]=array[i]

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 6 Bubblesortprogram:

Writethelogictoimplementbubblesort?
(http://skillgun.com/question/5579/commonprogramsforinterviews/javaprograms/bubblesortprogramwritethe
logictoimplementbubblesort)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

16/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassBubbleSort{

publicstaticvoidmain(String[]args){

int[]arr={12,23,43,34,3,6,7,1,9,6}

intn=arr.length

inttemp=0

for(inti=0i<ni++){

for(intj=1j<(ni)j++){

if(arr[j1]>arr[j]){

//swaptheelements!

temp=arr[j1]

arr[j1]=arr[j]

arr[j]=temp

for(intk=0k<arr.lengthk++)

System.out.println(arr[k])

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 7 AssumeDrawLine(x1,y1,x2,y2)functionwilldrawalinefrom(x1,y1)to(x2,y2).Usingthiswrite

onlythelogicforregularscale.
(Fx,Fy)istheorigin.
gisthegapbetweentwolines.
BListhelengthofbiggerline.
SListhelengthofsmallerline.
(http://skillgun.com/question/5580/commonprogramsforinterviews/javaprograms/assumedrawlinex1y1x2y2
functionwilldrawalinefromx1y1tox2y2usingthiswriteonlythelogicforregularscalefxfyistheorigingis
thegapbetweentwolinesblisthelengthofbiggerlineslisthelengthof)
h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

17/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

Toughness

A. publicclassLineExampleextendsjava.applet.Applet

@Override

publicvoidpaint(Graphicsarg0){

intfx=40

intfy=50

intbl=10

intsl=5

intg=5

for(inti=0i<15i++)

arg0.drawLine(fx,fy,fx,fy+bl)

for(intj=0j<4j++)

fx=fx+g

arg0.drawLine(fx,fy,fx,fy+sl)

fx=fx+g

publicstaticvoidmain(String[]args)

LineExamplele=newLineExample()

Graphicsg=null

le.paint(g)

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

18 /23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

1 8 Writeaprogramtodisplayanumberinwords

Eg:270176
OUT PUT :T WOSEVENZ EROONESEVENSIX
(http://skillgun.com/question/5581/commonprogramsforinterviews/javaprograms/writeaprogramtodisplaya
numberinwordseg270176outputtwosevenzeroonesevensix)
Toughness

A. publicclassNumbersToWords{

publicstaticvoidmain(String[]args){

intarr[]={2,7,0,1,7,6}

for(inti=0i<arr.lengthi++)

switch(arr[i]){

case0:

System.out.print("ZERO")

break

case1:

System.out.print("ONE")

break

case2:

System.out.print("TWO")

break

case3:

System.out.print("THREE")

break

case4:

System.out.print("FOUR")

break

case5:

System.out.print("FIVE")

break

case6:

System.out.print("SIX")

break

case7:

System.out.print("SEVEN")

break

case8:

System.out.print("EIGHT")

break

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

19/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

case9:

System.out.print("NINE")

break

default:

break

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

1 9 Decimaltobinaryconversionprogram:

Writeaprogramtoacceptadecimalnumberanddisplayitinthebinaryform.
(http://skillgun.com/question/5582/commonprogramsforinterviews/javaprograms/decimaltobinaryconversion
programwriteaprogramtoacceptadecimalnumberanddisplayitinthebinaryform)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

20/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassDecimalToBinary{

publicvoidprintBinaryFormat(intnumber){

intbinary[]=newint[25]

intindex=0

while(number>0){

binary[index++]=number%2

number=number/2

for(inti=index1i>=0i){

publicstaticvoidmain(Stringa[]){

DecimalToBinarydtb=newDecimalToBinary()

dtb.printBinaryFormat(4)

System.out.print(binary[i])

ShowAnswe randExplanat ion

Shareiton

Twitter

0SaysImportant
0PeopleLikeit
RateToughness

20 Binarytodecimalconversionprogram:

Writeaprogramtoacceptabinarynumberanddisplayitinthebinaryform.
(http://skillgun.com/question/5583/commonprogramsforinterviews/javaprograms/binarytodecimalconversion
programwriteaprogramtoacceptabinarynumberanddisplayitinthebinaryform)
Toughness

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

21/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

A. publicclassBinaryToDecimal{

publicintgetDecimalFromBinary(intbinary){

intdecimal=0

intpower=0

while(true){

if(binary==0){

}else{

inttmp=binary%10

decimal+=tmp*Math.pow(2,

binary=binary/10

power++

returndecimal

break

power)

publicstaticvoidmain(Stringa[]){

BinaryToDecimalbd=newBinaryToDecimal()

System.out.println("11===>

"+bd.getDecimalFromBinary(11))

System.out.println("110===>

"+bd.getDecimalFromBinary(110))

System.out.println("100110===>

"+bd.getDecimalFromBinary(100110))

Close Answe r

Shareiton

Twitter

Answe r:
De script ion:
0Comme nt s

StartDiscussion(http://skillgun.com/question/5583/commonprogramsfor
interviews/javaprograms/binarytodecimalconversionprogramwriteaprogramto
acceptabinarynumberanddisplayitinthebinaryform)

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

22/23

5 /2/2016

com m on program s for in t erviews java program s in t erview qu est ion s an d an swers paper 3 5 6 - skillgu n

T e llus
Submitnewquestion (http://skillgun.com/SubmitQuestions.aspx)
Questioniswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Question=true&q_id=5583&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
Answeriswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
Answer=true&q_id=5583&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)
Explanationiswrong (http://skillgun.com/TellUsAboutQuestion.aspx?
explanation=true&q_id=5583&p_id=356&typeid=1&count=1&topic_name=CommonProgramsforInterviews)

Readmorepapers: 1(http://skillgun.com/commonprogramsforinterviews/javaprograms/interviewquestionsand
answers/paper/356) 2(http://skillgun.com/commonprogramsforinterviews/javaprograms/interviewquestionsand
answers/paper/357)

2014PalleTechnologiesTermsofService(/Termsofservice.aspx)PrivacyPolicy(/PrivacyPolicy.aspx)AboutUs
(/AboutUs.aspx)ReportBug(/Reportbug.aspx)
Bookmarkt o Bookmarkto:Twitter

h t t p://skillgu n .com /com m on -program s-for-in t erviews/java-program s/in t erview-qu est ion s-an d-an swers/paper/3 5 6

23 /23

You might also like