[go: up one dir, main page]

0% found this document useful (0 votes)
3 views8 pages

Java PGM

The document contains multiple Java programs that demonstrate different functionalities. These include calculating the area of a circle, finding the factorial of a number using recursion, generating a pyramid of numbers, and providing greetings based on marks. Each program uses standard input and output for user interaction.

Uploaded by

Abhinav Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Java PGM

The document contains multiple Java programs that demonstrate different functionalities. These include calculating the area of a circle, finding the factorial of a number using recursion, generating a pyramid of numbers, and providing greetings based on marks. Each program uses standard input and output for user interaction.

Uploaded by

Abhinav Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

import java.io.

BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class area_of_a_circle {
public static void main(String[] args){
int radious= 0;
System.out.print("enter the radious of the circle :");

try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
radious=Integer.parseInt(br.readLine());
}
catch (NumberFormatException ne){
System.out.println("Invalid radious value"+ne);
System.exit(0);
}
catch (IOException ioe) {
System.out.println("IO Error :"+ioe);
System.exit(0);
}
double area = Math.PI*radious*radious;
System.out.println("Area of a circle is :" +area);
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class factorial_using_recursion {
public static void main(String[] args)throws NumberFormatException,IOException{
System.out.println("enter the number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a=Integer.parseInt(br.readLine());
int result = fact(a);
System.out.println("Factorial of the number is : "+result);
}

static int fact(int b) {


if (b<=1){
return 1;
}
else{
return b*fact(b-1);
}
}
}

import javax.swing.*;
import java.util.Scanner;
public class pyramid_of_numbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner st = new Scanner(System.in);
System.out.print("Enter the how much you want :");
int num = sc.nextInt();
System.out.print("which number should start :");
int start = st.nextInt();
int y = start;
if (start >num || start==0) {
for (int i = start; i <= num; i++) {
for (int j = start + 1; j <= i; j++) {
System.out.print(y + "\t");
y = y + 1;
}
System.out.println(" ");
}
}
else{
for (int i = start; i <= num + (num-1); i++) {
for (int j = start ; j <= i; j++) {
System.out.print(y + "\t");
y = y + 1;
}
System.out.println(" ");
}
}
}
}
import java.util.Scanner;
public class greet_msg_according_to_marks {
public static void main( String[] args){
Scanner st = new Scanner(System.in);
System.out.print("Enter the how much you want :");
int marks =st.nextInt();
switch(marks/10){
case 10:
case 9:
case 8:
System.out.println("Excellent");
break;
case 7:
System.out.println("Very Good");
break;
case 6:
System.out.println("Good");
break;
case 5:
System.out.println("Work Hard");
break;
case 4:
System.out.println("Poor");
break;
case 3:
case 2:
case 1:
case 0:
System.out.println("Very Poor");
break;
default:
System.out.println("Invalid value Entered");
}

}
}

You might also like