Week-1
Ans of Question - 1
Programme file name - Exercise1.java
import java.util.Scanner;
public class Exercise1
{
public static void
main(String[] args)
{
Scanner s =new
Scanner(System.in);
double
rad=s.nextDouble();
double para;
double area;
if(rad<=0)
{
System.out.println("Please enter non zero positive number");
}else
{
para=2*Math.PI*rad;
area=Math.PI*rad*rad;
System.out.println(para);
System.out.println(area);
}
}
}
Ans of Question - 2
Programme file name – Exercise2.java
{
public static void
main(String[] args)
{
Scanner s=new
Scanner(System.in);
int
x=s.nextInt();
int
y=s.nextInt();
int
z=s.nextInt();
int res=0;
if(x >= y
&& x >= z)
{
res=x;
}
else if(y
>= z)
{
res = y;
}
else{res=z;}
System.out.println(res);
}
}
Ans of Question - 3
Programme file name – Exercise3.java
import java.util.Scanner;
public class Exercise3
{
public static void
main(String[] args)
{
Scanner s=new
Scanner(System.in);
int
n=s.nextInt();
int
sum=0;
int
res=1;
int i=0;
while(res<=n)
{
if(i%2==0)
{
if(i%3==0)
{
sum=sum+i;
}
res=res+1;
}
i=i+1;
}
System.out.println(sum);
}
}
Ans of Question - 4
Programme file name – Exercise4.java
import java.util.Scanner;
public class Exercise4
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int res=0;
int temp=n;
int c=0,t;
while(n>0)
{
t=n%10;
n=n/10;
c=c+(t*t*t);
}
if(temp==c)
{
res=1;
}else{res=0;}
System.out.println(res);
}
}
Ans of Question - 5
Programme file name – Exercise5.java
import java.util.Scanner;
public class Exercise5
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
double mark_avg;
int res;
int i,s;
s=sc.nextInt();
int[] arr=new int[s];
for(i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
}
int max =arr[0];
double sum=arr[0];
for(i=1;i<arr.length;i++)
{
sum=sum+arr[i];
if(arr[i]>max)
max=arr[i];
}
res=max;
mark_avg=sum/(arr.length);
System.out.println(res);
System.out.println(mark_avg);
}
}
No comments: