Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
121 views

Write A Program To Print Your Name.: Source Code

The document contains 6 Java programs that demonstrate different programming concepts: 1. A program to print a user's name 2. A program to convert a price in decimal format to paise 3. A program to convert temperature from Fahrenheit to Celsius 4. A program to calculate the sum of a series up to a given value of n 5. A program to find the sum of digits and reverse of an integer 6. A program to calculate the factorial of a number using recursion

Uploaded by

RAHUL DAS
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)
121 views

Write A Program To Print Your Name.: Source Code

The document contains 6 Java programs that demonstrate different programming concepts: 1. A program to print a user's name 2. A program to convert a price in decimal format to paise 3. A program to convert temperature from Fahrenheit to Celsius 4. A program to calculate the sum of a series up to a given value of n 5. A program to find the sum of digits and reverse of an integer 6. A program to calculate the factorial of a number using recursion

Uploaded by

RAHUL DAS
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/ 4

1. Write a program to print your name.

Source code
import java.util.Scanner;
public class PrintName {
public static void main(String args[])
{
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter your name");
String name = keyboard.nextLine();
System.out.println("Hello " + name);
}

Output
Enter your name
ram
Hello ram

2.Write a program to read the price of an item in the decimal form (like 75.95)
and print the output in paise (like 7595 paise).

Source code
import java.util.Scanner;
public class RupeesToPaise{
public static void main(String args[])
{
Scanner keyboard =new Scanner(System.in);
System.out.println("Enter the price:");
double price=keyboard.nextDouble();
System.out.println("Price in paise is"+ price*100);
}
}
Output

Enter the price:


75.95
Price in paise is 7595.0
3.Write a program to convert the given temperature in Fahrenheit to Celsius
using the following conversion formula:
C = (F-32)/1.8
Source code

import java.util.Scanner;
public class temperature {
public static void main(String args[])
{
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter Farheniet Temperature:");
double F=keyboard.nextInt();
double C=((F-32)/9)*5;
System.out.println("Celcius Temperature:"+C);
}

Output
Enter Farheniet Temperature:
42
Celcius Temperature:5.555555555555555

4.Write a program to determine sum of the following series for given value of n:
(1 + 1/2 + 1/3 + …… + 1/n). Print the result up to two decimal places
Source code
import java.util.Scanner;
public class SeriesSum {
public static void main(String args[])
{
double sum=0;
int i;
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter the value of n:");
int n=keyboard.nextInt();
for(i=1;i<=n;i++)
{
sum=sum +(float)1/i;
}
System.out.println("Sum of Series is "+ sum);
}

}
Output
Enter the value of n:
5
Sum of Series is 2.283333346247673

5.Write a program to find the sum of digits and reverse of a given integer
number

Source code

import java.util.Scanner;
public class digit
{
public static void main(String[] args)
{
int n, a, m = 0, sum = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
do
{
a = n % 10;
m = m * 10 + a;
sum = sum + a;
n = n / 10;
}
while( n > 0);
System.out.println("Reverse:"+m);
System.out.println("Sum of digits:"+sum);
}
}
Output
Enter any number:52
Reverse:25
Sum of digits:7

6. Write a program to find the factorial of a given integer number using


recursion

Source code

import java.util.Scanner;
class factorial{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number:");

int num = scanner.nextInt();

int factorial = fact(num);


System.out.println("Factorial of entered number is:
"+factorial);
}
static int fact(int n)
{
int output;
if(n==1){
return 1;
}

output = fact(n-1)* n;
return output;
}
}
Output
Enter the number:
5
Factorial of entered number is: 120

You might also like