Write A Program To Print Your Name.: Source Code
Write A Program To Print Your Name.: Source Code
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
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
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:");
output = fact(n-1)* n;
return output;
}
}
Output
Enter the number:
5
Factorial of entered number is: 120