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

567 Java ii

The document contains three Java programs: one for calculating simple interest based on user input for principal, rate, and time; another for calculating the circumference of a circle given its radius; and a third for determining if a user-input integer is positive, negative, or zero. Each program utilizes the Scanner class for input and outputs the results to the console. These examples demonstrate basic programming concepts such as user input, conditional statements, and mathematical calculations.

Uploaded by

coderknowbody
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

567 Java ii

The document contains three Java programs: one for calculating simple interest based on user input for principal, rate, and time; another for calculating the circumference of a circle given its radius; and a third for determining if a user-input integer is positive, negative, or zero. Each program utilizes the Scanner class for input and outputs the results to the console. These examples demonstrate basic programming concepts such as user input, conditional statements, and mathematical calculations.

Uploaded by

coderknowbody
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5.

import java.util.Scanner;

public class SimpleInterestCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the principal amount:");


double principal = scanner.nextDouble();

System.out.println("Enter the rate of interest (in percentage):");


double rate = scanner.nextDouble();

System.out.println("Enter the time period (in years):");


double time = scanner.nextDouble();

double simpleInterest = (principal * rate * time) / 100;

System.out.println("The simple interest is: " + simpleInterest);


}
}

6.

import java.util.Scanner;

public class Circumference {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter radius (r): ");


double r = scanner.nextDouble();

double pi = 22.0 / 7.0;


double C = 2 * pi * r;

System.out.println("Circumference (C): " + C);


}
}
7.

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter an integer number: ");
int number = scanner.nextInt();

if (number > 0) {
System.out.println("The number is positive.");
} else if (number < 0) {
System.out.println("The number is negative.");
} else {
System.out.println("The number is zero.");
}
}
}

You might also like