0% found this document useful (0 votes)
4 views3 pages

Java_Practice_Questions_and_Solutions_Corrected

The document contains Java practice questions focused on basic programming concepts, including a Grade Calculator that assigns grades based on user input marks and an Even and Odd Counter that counts the number of even and odd integers from user input. Each section includes the logic behind the solution and the corresponding Java code. The document serves as a resource for practicing Java programming skills.

Uploaded by

MAlik Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java_Practice_Questions_and_Solutions_Corrected

The document contains Java practice questions focused on basic programming concepts, including a Grade Calculator that assigns grades based on user input marks and an Even and Odd Counter that counts the number of even and odd integers from user input. Each section includes the logic behind the solution and the corresponding Java code. The document serves as a resource for practicing Java programming skills.

Uploaded by

MAlik Ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Practice Questions with Solutions and Code

1. Grade Calculator

-------------------

Logic: Take the user's marks, check which range they fall into, and print the appropriate grade using

if-else conditions.

Code:

import java.util.Scanner;

public class GradeCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter marks: ");

int marks = scanner.nextInt();

if (marks >= 90) {

System.out.println("Grade: A");

} else if (marks >= 80) {

System.out.println("Grade: B");

} else if (marks >= 70) {

System.out.println("Grade: C");

} else if (marks >= 60) {

System.out.println("Grade: D");

} else {

System.out.println("Grade: F");
}

2. Even and Odd Counter

------------------------

Logic: Loop through 10 numbers, use num % 2 to check if even or odd, and keep count.

Code:

import java.util.Scanner;

public class EvenOddCounter {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int evenCount = 0, oddCount = 0;

for (int i = 1; i <= 10; i++) {

System.out.print("Enter number " + i + ": ");

int num = scanner.nextInt();

if (num % 2 == 0) {

evenCount++;

} else {

oddCount++;

System.out.println("Even numbers: " + evenCount);

System.out.println("Odd numbers: " + oddCount);


}

... (Truncated for brevity, but follows the same structure for other solutions.)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy