[go: up one dir, main page]

0% found this document useful (0 votes)
22 views5 pages

3 Jun 2024 Java - Tejal Class

The document contains code for three Java programs - one that calculates change for a dollar amount in coins, one that sorts three integers in non-decreasing order, and one that validates and generates the 10-digit ISBN from the first 9 digits entered as an integer.

Uploaded by

Soumya Roy
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)
22 views5 pages

3 Jun 2024 Java - Tejal Class

The document contains code for three Java programs - one that calculates change for a dollar amount in coins, one that sorts three integers in non-decreasing order, and one that validates and generates the 10-digit ISBN from the first 9 digits entered as an integer.

Uploaded by

Soumya Roy
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/ 5

import java.util.

Scanner;

public class ComputeChange

public static void main(String[] args)

// Create a Scanner

Scanner input = new Scanner(System.in);

// Receive the amount

System.out.print("Enter an amount in double, for example 11.56: ");

double amount = input.nextDouble();

int remainingAmount = (int)(amount * 100);

// Find the number of one dollars

int numberOfOneDollars = remainingAmount / 100;

remainingAmount = remainingAmount % 100;

// Find the number of quarters in the remaining amount

int numberOfQuarters = remainingAmount / 25;

remainingAmount = remainingAmount % 25;

// Find the number of dimes in the remaining amount

int numberOfDimes = remainingAmount / 10;

remainingAmount = remainingAmount % 10;

// Find the number of nickels in the remaining amount

int numberOfNickels = remainingAmount / 5;

remainingAmount = remainingAmount % 5;

// Find the number of pennies in the remaining amount

int numberOfPennies = remainingAmount;

// Display results

System.out.println("Your amount " + amount + " consists of");

if(numberOfOneDollars>0 && numberOfOneDollars==1)

System.out.println(" " + numberOfOneDollars + " dollar");

else if(numberOfOneDollars>0 && numberOfOneDollars>1)

System.out.println(" " + numberOfOneDollars + " dollars");


if(numberOfQuarters>0 && numberOfQuarters==1)

System.out.println(" " + numberOfQuarters + " quarter ");

else if(numberOfQuarters>0 && numberOfQuarters>1)

System.out.println(" " + numberOfQuarters + " quarters ");

if(numberOfDimes>0 && numberOfDimes==1)

System.out.println(" " + numberOfDimes + " dimes ");

else if(numberOfDimes>0 && numberOfDimes>1)

System.out.println(" " + numberOfDimes + " dimes");

if(numberOfNickels>0 && numberOfNickels==1)

System.out.println(" " + numberOfNickels + " nickel");

else if(numberOfNickels>0 && numberOfNickels>1)

System.out.println(" " + numberOfNickels + " nickels");

if(numberOfPennies>0 && numberOfPennies==1)

System.out.println(" " + numberOfPennies + " penny");

else if(numberOfPennies>0 && numberOfPennies>1)

System.out.println(" " + numberOfPennies + " pennies");

//3.8 Write a program that prompts the user to enter three integers and display the integers in non-
decreasing order.

import java.util.Scanner;

public class SortThreeIntegers

public static void main(String[] args)


{

int x=0,y=0,z=0;

// Create a Scanner

Scanner sc = new Scanner(System.in);

// Receive three integers

System.out.print("Enter three integers: ");

int a=sc.nextInt();

int b=sc.nextInt();

int c=sc.nextInt();

if((a<b && a<c)&&(b<c))

x=a;

y=b;

z=c;

else if((a<b && a<c)&&(c<b))

x=a;

y=c;

z=b;

else if((b<a && b<c)&&(a<c))

x=b;

y=a;

z=c;

else if((b<a && b<c)&&(c<a))

x=b;

y=c;
z=a;

else if((c<a && c<b)&&(a<b))

x=c;

y=a;

z=b;

else if((c<a && c<b)&&(b<a))

x=c;

y=b;

z=a;

System.out.println("Integers in non-decreasing order: \n"+x+"\n"+y+"\n"+z);

//3.9 Write a program that prompts the user to enter the first 9 digits and displays the 10-digit ISBN
(including leading zeros). Your program should read the input as an integer.

import java.util.Scanner;

public class CheckISBN

public static void main(String[] args)

int Sum=0,m,d=9,x;

// Create a Scanner

Scanner sc = new Scanner(System.in);

// Receive three integers

System.out.print("Enter the first 9 digits of an ISBN as integer: ");


long a=sc.nextLong();

long b=a;

while(b>0)

m=(int)b%10;

Sum=Sum+(m*d);

d--;

b=b/10;

x=Sum%11;

if(x==10)

System.out.println("The ISBN-10 number is : "+a+"X");

else

System.out.println("The ISBN-10 number is : "+a+""+x);

You might also like