SCANN

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Write a program to input five integers and find their average.

import java.util.*;
class Q2
{
static void main()
{
Scanner sc=new Scanner(System.in); int a,b,c,d,e;
float av;
System.out.println(“Enter 5 integers:”); a=sc.nextInt();
b=sc.nextInt(); c=sc.nextInt(); d=sc.nextInt(); e=sc.nextInt(); av=(float)
(a+b+c+d+e)/5;
System.out.println(“Average=”+av);
}
}
Write a program to input the Principal, Rate and Time for a certain amount of money
and print the Simple Interest.

import java.util.*;
class Q5
{
static void main()
{
Scanner sc=new Scanner(System.in); float p,r,t,si;
System.out.println(“Enter the principal:”); p=sc.nextFloat(); System.out.println(“Enter
the rate:”); r=sc.nextFloat(); System.out.println(“Enter the time:”); t=sc.nextFloat();
si=(p*r*t)/100; System.out.println(“Simple Interest=”+si);
}

}
Write a program to input three integers and find the sum of the last digit of the numbers. For
example if the inputs are: 12
26, 35 Output:
Sum of the last digit of the integers are: 13

Ans.

import java.util.*;
class Q10
{
static void main()
{
Scanner sc=new Scanner(System.in); int a,b,c,s;
System.out.println(“Enter the 3 integers:”); a=sc.nextInt();
b=sc.nextInt(); c=sc.nextInt(); s=a%10+b%10+c%10;
System.out.println( “Sum of the last digits=”+s);
}

You might also like