Print the Multiplication Table in Java Description: Take an integer number N as input…
- User
Print the Multiplication Table in Java
Description: Take an integer number N as input from the user and print multiplication table as shown below -
Sample input: num = 5
Output-
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
- Assistant
Solution:
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
codeScanner in = new Scanner(System.in); System.out.print("Enter a number: "); int num = in.nextInt(); for(int i=1; i<=10; i++) { System.out.println(num + " x " + i + " = " + (num*i)); }}
}
// Sample output for num = 5
// 5 x 1 = 5
// 5 x 2 = 10
// 5 x 3 = 15
// 5 x 4 = 20
// 5 x 5 = 25
// 5 x 6 = 30
// 5 x 7 = 35
// 5 x 8 = 40
// 5 x 9 = 45
// 5 x 10 = 50
- User
Calculate percentage and display the GPA in Java
Description: WAP in Java to take the total marks and the marks obtained by a Student. Then using your programming skills calculate the percentage obtained by a student along with the GPA.
GPA Grading Criteria:
0 - 59% - Grade F, GPA = 0.0
60 - 69% - Grade D, GPA = 1.0
70 - 79% - Grade C, GPA = 2.0
80 - 89% - Grade B, GPA = 3.0
90 - 100% - Grade A, GPA = 4.0
Sample input: Marks Obtained by a Student: 650
Total Marks: 700
- Assistant
Solution:
import java.util.Scanner;
public class PercentageAndGPA {
public static void main(String[] args) {
codeScanner in = new Scanner(System.in); System.out.print("Enter marks obtained: "); float marks = in.nextFloat(); System.out.print("Enter total marks: "); float totalMarks = in.nextFloat(); float percentage = (marks / totalMarks) * 100; System.out.println("Percentage = " + percentage + "%"); if(percentage >= 90) { System.out.println("Grade: A"); System.out.println("GPA: 4.0"); } else if(percentage >= 80) { System.out.println("Grade: B"); System.out.println("GPA: 3.0"); } else if(percentage >= 70) { System.out.println("Grade: C"); System.out.println("GPA: 2.0"); } else if(percentage >= 60) { System.out.println("Grade: D"); System.out.println("GPA: 1.0"); } else { System.out.println("Grade: F"); System.out.println("GPA: 0.0"); } - User
Swap two integer numbers in Java
Description: Take an integer number a and b as input from the user. Using your Java skills to swap their values and print the output.
Sample input: numA = 63
numB = 15
Output: numA = 15
numB = 63
- Assistant
Solution:
import java.util.Scanner;
public class SwapTwoNumbers {
public static void main(String[] args) {
codeScanner in = new Scanner(System.in); System.out.print("Enter value of a: "); int a = in.nextInt(); System.out.print("Enter value of b: "); int b = in.nextInt(); System.out.println("Before swapping:"); System.out.println("a = " + a + ", b = " + b); // swapping the values of a and b int temp = a; a = b; b = temp; System.out.println("After swapping:"); System.out.println("a = " + a + ", b = " + b);}
}
// Sample output for a = 63 and b = 15
// Before swapping:
// a = 63, b = 15
// After swapping:
// a = 15, b = 63
- User
Menu driven app - Even/Odd Checker program in java
Description: Create a menu driven command-line based application in Java to take an integer number N as input from the user and display if the given number is an Even Number or the Odd Number.
Sample input:
Menu based app - Even/Odd Checker
Please enter the number: 15
The given number - 15 is an ODD Number
Do you want to Continue: y
Menu based app - Even/Odd Checker
Please enter the number: 62
The given number - 62 is an EVEN Number
Do you want to Continue: y
Menu based app - Even/Odd Checker
Please enter the number: 79
The given number - 62 is a ODD Number
Do you want to Continue: n
- Assistant
Solution:
import java.util.Scanner;
public class EvenOddChecker {
public static void main(String[] args) {
codeScanner in = new Scanner(System.in); char choice; do { System.out.println("Menu based app - Even/Odd Checker"); System.out.print("Please enter the number: "); int num = in.nextInt(); if(num % 2 == 0) { System.out.println("The given number - " + num + " is an EVEN Number"); } else { System.out.println("The given number - " + num + " is an ODD Number"); } System.out.print("Do you want to Continue: "); choice = in.next().charAt(0); } while(choice == 'y' || choice == 'Y'); - User
Menu driven app - Unit conversion for Distance in Java
Description: Create a menu driven command-line based application in Java to convert the N unit distance to the requested unit.
Menu based app - Unit conversion for Distance
CM to M
M to KM
KM to M
M to CM
Enter your menu - 1
Please enter the CM Value: 150
150 CM = 1.5 M
Do you want to Continue: y
Menu based app - Unit conversion for Distance
CM to M
M to KM
KM to M
M to CM
Enter your menu - 2
Please enter the M Value: 2500
2500 M = 2.5 KM
Do you want to Continue: n
- Assistant
Solution:
import java.util.Scanner;