0% found this document useful (0 votes)
7 views

Java Program

The document contains multiple Java programs that perform various tasks such as swapping integers, checking for prime numbers, extracting digits from a three-digit number, calculating salary deductions, finding the second largest number, checking divisibility, calculating taxi fare, computing maturity amounts, converting temperature scales, and calculating volumes of different solids. Each program uses the Scanner class for user input and includes basic control structures like if-else statements and switch cases. The code snippets demonstrate fundamental programming concepts in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java Program

The document contains multiple Java programs that perform various tasks such as swapping integers, checking for prime numbers, extracting digits from a three-digit number, calculating salary deductions, finding the second largest number, checking divisibility, calculating taxi fare, computing maturity amounts, converting temperature scales, and calculating volumes of different solids. Each program uses the Scanner class for user input and includes basic control structures like if-else statements and switch cases. The code snippets demonstrate fundamental programming concepts in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1

import java.util.Scanner;

public class swap_digit

public static void main(String args[])

System.out.println("Enter 1st integer");

Scanner input = new Scanner(System.in);

int a = input.nextInt();

System.out.println("Enter 2nd integer");

int b = input.nextInt();

System.out.println("Before swaping a="+a+",b="+b);

a=a+b;

b=a-b;

a=a-b;

System.out.println("After swaping a="+a+",b="+b);

2
import java.util.Scanner;

public class primeInteger

public static void main(String args[])

int i,m=0,flag=0;

System.out.println("Enter the integer to be checked:");

Scanner input = new Scanner(System.in);

int n = input.nextInt();

m=n/2;

if(n==0||n==1)

System.out.println(n+" is not prime number");

else
{

for(i=2;i<=m;i++)

if(n%i==0){

System.out.println(n+" is not prime number");

flag=1;

break;

if(flag==0) { System.out.println(n+" is prime number");

3
import java.util.Scanner;

public class threedigits

public static void main(String args[])

System.out.println("Enter a three digit integer");

Scanner input = new Scanner(System.in);

int number = input.nextInt();

int digit1 = number / 100;

int digit2 = (number % 100)/10;

int digit3 = number % 10;

System.out.println(digit1);

System.out.println(digit2);

System.out.println(digit3);

4
import java.util.Scanner;

public class salary

public static void main(String args[])

double p_f,h_r,edu;

System.out.println("Enter the salary of the employee:");

Scanner input = new Scanner(System.in);

double s = input.nextDouble();

p_f=s*.14;

s=s-p_f;

h_r=s*.15;

edu=s*.25;

System.out.println("Amount deducted as Provident fund:"+p_f);

System.out.println("Amount spent on rent:"+h_r+"and on education:"+edu);

5
import java.util.Scanner;

public class second_largest

public static void main(String args[])

int first,second;

System.out.println("Enter the 1st number:");

Scanner input = new Scanner(System.in);

int a = input.nextInt();

System.out.println("Enter the 2nd number:");

int b = input.nextInt();

System.out.println("Enter the 3rd number:");

int c = input.nextInt();

if (a<b)

second=a;

first=b;
}

else

second=b;

first=a;

if ((first > c) && (second < c))

second=c;

if (c>first)

second=first;

System.out.println("Second largest number is: "+second);

6
import java.util.Scanner;

public class divisibility

public static void main(String args[])

System.out.println("Enter the number:");

Scanner input = new Scanner(System.in);

int a = input.nextInt();

if (a%15==0)

System.out.println("Number is divisible by 3 as well as by 5 ");

else

if (a%3==0)

{
System.out.println("Number is divisible by 3 and not by 5");

else

if (a%5==0)

System.out.println("Number is divisible by 5 and not by 3");

else

System.out.println("Number is neither divisible by 5 nor by 3");

7
import java.util.Scanner;

public class taxi_fare

public static void main(String args[])

double price;

System.out.println("Enter the distance:");

Scanner input = new Scanner(System.in);

double d = input.nextDouble();

if(d>25)

price=280+(d-25)*5;

else

if(d>15)
{

price=200+(d-15)*8;

else

if(d>5)

price=100+(d-5)*10;

else

price=100;

System.out.println("Taxi No.:");

System.out.println("Distance covered:"+d);

System.out.println("Amount:"+price);

8
import java.util.Scanner;

public class amount

public static void main(String args[])

double maturity;

System.out.println("Enter the sum of money deposited::");

Scanner input = new Scanner(System.in);

double p = input.nextDouble();

System.out.println("Enter the number of days::");

double d = input.nextDouble();
if(d>365)

maturity=p+p*0.085*d/365;

else

if(d==365)

maturity=p+p*0.09*d/365;

else

if(d>=181)

maturity=p+p*0.075*d/365;

else

maturity=p+p*0.055*d/365;

System.out.println("Maturity amount:"+maturity);

9
import java.util.Scanner;

public class scale_change

public static void main(String args[])

System.out.println("\n***Menu***");

System.out.println("1. Fahrenheit to Celsius");

System.out.println("2. Celsius to Fahrenheit");

System.out.println("Enter the number (1-2): ");

Scanner input = new Scanner(System.in);

int option = input.nextInt();

double c=0,f=0;

switch(option)

case 1:

System.out.println("Enter temperature in Fahrenheit:");

f=input.nextDouble();

c=5/9.0*(f-32);

System.out.println("Temperature in Celsius is "+c);

break;

case 2:

System.out.println("Enter temperature in Celsius:");

c=input.nextDouble();

f=1.8*c+32;

System.out.println("Temperature in Fahrenheit is "+f);

Break;

10
import java.util.Scanner;

public class solid

public static void main(String args[])

System.out.println("\n***Menu***");

System.out.println("1. Cuboid");

System.out.println("2. Cylinder");

System.out.println("3. Cone");

System.out.println("Enter the number (1-3)corresponding to the solid to find the volume: ");

Scanner input = new Scanner(System.in);

int option = input.nextInt();

double volume=0,p=22/7;

double l=0,b=0,h=0,r=0;

switch(option)

case 1:

System.out.println("Enter length");

l=input.nextDouble();

System.out.println("Enter breathth");

b=input.nextDouble();

System.out.println("Enter height");

h=input.nextDouble();

volume=l*b*h;

break;

case 2:

System.out.println("Enter height");

h=input.nextDouble();

System.out.println("Enter radius");

r=input.nextDouble();

volume=p*r*r*h;

break;

case 3:

System.out.println("Enter height");

h=input.nextDouble();
System.out.println("Enter radius");

r=input.nextDouble();

volume=p*r*r*h/3.0;

break;

System.out.println("Volume of the solid is "+volume);

You might also like