Java program
1) Average of 3 numbers
package Hw;
import java.util.Scanner;
public class average {
public static void main(String[] args) {
int a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a,b & c values:");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
double avg=(a+b+c)/3.0;
System.out.println("Average of no. is: "+avg);
sc.close();
}
}
2) Area of circle
package bbg;
import java.util.Scanner;
public class area {
public static void main(String[] args) {
System.out.println("Enter radius:");
Scanner sc=new Scanner (System.in);
double r=sc.nextDouble();
double area= 3.14 * r * r;
System.out.println("Area: "+area);
}
}
3) Student details
package bbg;
import java.util.Scanner;
public class student {
public static void main(String[] args) {
System.out.println("Enter name: ");
Scanner sc=new Scanner(System.in);
String name =sc.next();
System.out.println("Enter age: ");
int age=sc.nextInt();
System.out.println("Enter marks of COA,DM, OS");
int coa,dm, os;
coa=sc.nextInt();
dm=sc.nextInt();
os=sc.nextInt();
double perc=(coa+dm+os)/3.0;
System.out.println("Name: "+name+"Age "+age+" COA: " +coa+" DM: "+dm+" OS: "+os+"Percentage :"+perc);
sc.close();
}
}
0 Comments