Question: Picnic Time
Tomorrow is the local picnic day and the parents are excited to take their children to the park. The organizers are giving some chocolates to the children. We know that every family has 2 children.
The organizers will give chocolates corresponding to the age of the children. So a family with a four-year old and a 7-year old child will get 11 chocolates.
However, if any of the child in that family is a teenager (between 13 to 19 inclusive), then that family receives a total of 40 chocolates.
Write a method Met that takes as parameters 2 integers, each storing the age of a child. You have to print the number of chocolates the family will get.
Only write the method - assume that the Class & main method have been defined.
Use the System.out.println() statement for printing.
Example Input: 4 7
Output: 11
Example Input: 11 20
Output: 31
Example Input: 5 13
Output: 40
Answers
Answered by
4
METHOD......
public static void met(int a,int b){
if((a>=13&&a<=19)||(b>=13&&b<=19)){
System.out.println("40");
}
else{
System.out.println(a+b);
}
}
COMPLETE CODE.......
import java.util.Scanner;
public class Program
{
public static void met(int a,int b){
if((a>=13&&a<=19)||(b>=13&&b<=19)){
System.out.println("40");
}
else{
System.out.println(a+b);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int age1=sc.nextInt();
int age2=sc.nextInt();
Program.met(age1,age2);
}
}
nitish8089:
i will done left question tommorow..
Similar questions