All Programming Codding Solution Fo
All Programming Codding Solution Fo
Solution :-
import java.util.Scanner;
System.out.println("The sum of " + num1 + " and " + num2 + " is: " + sum);
scanner.close();
}
}
Q NO.2. WAP to input principal amount, rate and time. Calculate its simple interest
and compound interest.
Solution :-
import java.util.Scanner;
Q NO.3.WAP to input the radius of any circle and find its area and perimeter.
Solution :-
import java.util.Scanner;
// Calculate area
double area = Math.PI * radius * radius;
Solution :-
import java.util.Scanner;
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.");
}
input.close();
}
}
Q NO.5.WAP to input the marks of three subject (Out of 100) and calculate its
percentage, total marks,total distinction in subjects and display fail if he/she
gets marks less than 30 in any one of the subjects.
Solution :-
import java.util.Scanner;
input.close();
}
}
Solution :- Here's the Java code for finding the greatest of three numbers using
both nested if statements and the ternary operator:
(i) Using nested if statements:
import java.util.Scanner;
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int greatest;
{
if (num2 > num3)
{
greatest = num2;
}
else
{
greatest = num3;
}
}
import java.util.Scanner;
int greatest = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 >
num3) ? num2 : num3);
Q NO.7. WAP to input two numbers and perform addition, substraction and
multiplication by using switch statement.
Solution :- A Java program that takes two numbers as input and performs addition,
subtraction, and multiplication using a switch statement: java
import java.util.Scanner;
switch (operation)
{
case '+':
result = num1 + num2;
System.out.println("The addition of " + num1 + " and " + num2 + "
is: " + result);
break;
case '-':
result = num1 - num2;
System.out.println("The subtraction of " + num1 + " and " + num2 +
" is: " + result);
break;
case '*':
result = num1 * num2;
System.out.println("The multiplication of " + num1 + " and " + num2
+ " is: " + result);
break;
default:
System.out.println("Invalid operation!");
break;
}
scanner.close();
}
}
Q NO.7.WAP to display odd and even numbers between 5 to 50 and also display its sum
separately.
Solution :- A Java program that displays the odd and even numbers between 5 and 50,
along with their respective sums:
System.out.println("Odd Numbers:");
for (int i = start; i <= end; i++)
{
if (i % 2 != 0)
{
System.out.print(i + " ");
oddSum += i;
}
}
System.out.println("\nSum of odd numbers: " + oddSum);
System.out.println("\nEven Numbers:");
for (int i = start; i <= end; i++)
{
if (i % 2 == 0)
{
System.out.print(i + " ");
evenSum += i;
}
}
System.out.println("\nSum of even numbers: " + evenSum);
}
}
Q NO.8. WAP to display and the sum of all numbers between 15 to 100, which is
divisible by 7.
Solution :-A Java program that displays the numbers between 15 and 100 that are
divisible by 7 and calculates their sum:
public class DivisibleBySeven
{
public static void main(String[] args)
{
int start = 15;
int end = 100;
int sum = 0;
Solution:- A Java program that allows you to input two numbers and swap them using
different methods:
import java.util.Scanner;
int temp;
temp = num1;
num1 = num2;
num2 = temp;
System.out.println("After swapping:");
System.out.println("First number: " + num1);
System.out.println("Second number: " + num2);
}
}
import java.util.Scanner;
public class SwapNumbers
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("After swapping:");
System.out.println("First number: " + num1);
System.out.println("Second number: " + num2);
}
}
import java.util.Scanner;
System.out.println("After swapping:");
System.out.println("First number: " + num1);
System.out.println("Second number: " + num2);
}
}
Q NO.10. WAP to input a number and find all the prime number between 5 to 100.
Solution:-import java.util.Scanner;
return true;
}
}