- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Input in Java
Chapter 6
Input in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Student Details & Percentage Calculation
Write a program in Java, using the Scanner methods, to read and display the following details:
Name - as a String data type
Roll Number - as an integer data type
Marks in 5 subjects - as a float data type
Compute and display the percentage of marks.
import java.util.Scanner;
public class StudentPercentage {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input student details
System.out.print("Enter Student Name: ");
String name = sc.nextLine();
System.out.print("Enter Roll Number: ");
int rollNo = sc.nextInt();
float totalMarks = 0;
System.out.println("Enter marks in 5 subjects:");
for (int i = 1; i <= 5; i++) {
System.out.print("Subject " + i + ": ");
float marks = sc.nextFloat();
totalMarks += marks;
}
// Calculate percentage
float percentage = (totalMarks / 500) * 100;
// Display output
System.out.println("\n--- Student Details ---");
System.out.println("Name: " + name);
System.out.println("Roll Number: " + rollNo);
System.out.println("Percentage: " + percentage + "%");
sc.close();
}
}
Output
SAMPLE INPUT : Enter Student Name: Rahul Sharma Enter Roll Number: 25 Enter marks in 5 subjects: Subject 1: 78 Subject 2: 85 Subject 3: 90 Subject 4: 88 Subject 5: 79 SAMPLE OUTPUT : --- Student Details --- Name: Rahul Sharma Roll Number: 25 Percentage: 84.0%
Explanation
- The Scanner class is used to read input values.
- nextLine() is used for reading the name (String).
- nextInt() is used for reading the roll number.
- nextFloat() is used for reading marks.
- A for loop is used to read marks of 5 subjects.
- Percentage is calculated using the formula:
Percentage = (Total Marks) / 500 × 100
