You are on page 1of 6

Java program

1.AddTwoNums
Problem Statement
Given two numbers as input, calculate the sum of the numbers.
Sample Input #1
add(289,266)

Sample Output #1
555

Sample Input #2
add(-100,67)

Sample Output #2
-33

Code:
public class AddTwoNums {

public static void main(String args[]){


AddTwoNums obj= new AddTwoNums();
int result = obj.add(289,266);
System.out.println(result);
}
//write your code here
public int add(int num1, int num2){
int sum = num1+num2;
System.out.println(sum);
return sum;

2. RunsInSeries
Problem Statement
The scores of a batsman in the five matches of a one day international series have been
provided. Calculate the total number of runs the batsman scored in the series.
Sample Input #1
computeRuns(51,0,96,44,70)

Sample Output #1
261

Sample Input #2
computeRuns(12,8,21,22,0)

Sample Output #2
63

Code:
public class RunsInSeries {

public static void main(String args[]){


RunsInSeries obj = new RunsInSeries();
int result = obj.computeRuns(51,0,96,44,70);
System.out.println(result);
}

public int computeRuns(int inn1, int inn2, int inn3, int inn4, int inn5){
//write your code here

int sum=inn1+inn2+inn3+inn4+inn5;
System.out.println("total runs of batsman in 5 matches"+sum);
return sum;
}
}

3. SecondToHours
Problem Statement
Given the time in number of seconds, find out how many hours have been completed
Sample Input #1
toHours(22125)

Sample Output #1
6

Sample Input #2
toHours(2511)

Sample Output #2
0

Sample Input #3
toHours(86208)

Sample Output #3
23

Code:
public class SecondToHours {

public static void main(String args[]) {

SecondToHours obj = new SecondToHours();


int result = obj.toHours(22125);
System.out.println(result);
}

public int toHours(int seconds) {


return seconds/3600;
}
}

4.HundredsDigit
Problem Statement
Given a 4 digit number as input, find the value of its hundreds digit.
Sample Input #1
hundredsDigit(10567)

Sample Output #1
5

Sample Input #2
hundredsDigit(890)

Sample Output #2
8

Sample Input #3
hundredsDigit(41)

Sample Output #3
0

Code:

RequiredRunRate
Problem Statement
A team is chasing the target set in a one day international match. The objective is to
compute the required run rate. The following have provided as input: target, maxOvers,
currentScore, oversBowled.
Sample Input #1
runrateRequired(326,49,210,33)

Sample Output #1
7.25

Sample Input #2
runrateRequired(326,49,210,33)

Sample Output #2
7.25

Code:
public class RequiredRunRate {

public static void main(String args[]){


RequiredRunRate obj = new RequiredRunRate();
double result = obj.runrateRequired(326,49,210,33);
System.out.println(result);
}

public double runrateRequired(int target, int maxOvers, int currentScore, int oversBowled){

//write your code


double a=target-currentScore;
double b=maxOvers-oversBowled;
return a/b;
}

5. Make3Digit
Problem Statement
Given a digit as input, create a 3 digit number in which all the digits are the same as the input
digit.
Sample Input #1
make3DigitNum(4)

Sample Output #1
444

Sample Input #2
make3DigitNum(1)

Sample Output #2
111

Code: