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.
Answers
Answer:
import java.util.Scanner;
public class KboatMarks
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
String name = in.nextLine();
System.out.print("Enter Roll Number: ");
int rollNo = in.nextInt();
System.out.print("Enter Marks in 1st Subject: ");
float m1 = in.nextFloat();
System.out.print("Enter Marks in 2nd Subject: ");
float m2 = in.nextFloat();
System.out.print("Enter Marks in 3rd Subject: ");
float m3 = in.nextFloat();
System.out.print("Enter Marks in 4th Subject: ");
float m4 = in.nextFloat();
System.out.print("Enter Marks in 5th Subject: ");
float m5 = in.nextFloat();
float t = m1 + m2 + m3 + m4 + m5;
float p = t / 500 * 100;
System.out.println("Percentage Marks = " + p);
in.close();
}
Explanation:
Hope this helps you thanku 。◕‿◕。