Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Accept name and marks in two subjects and print total marks

0 votes
Write a program to accept the name and marks of a student in two subjects and print the name and total marks of the student.
asked by Hash_2125
edited by Ranjith

1 Answer

0 votes

Program

import java.util.Scanner;

public class Student {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter name: ");
        String name = scanner.nextLine();
        System.out.print("Enter marks in first subject: ");
        int marks1 = scanner.nextInt();
        System.out.print("Enter marks in second subject: ");
        int marks2 = scanner.nextInt();
        int totalMarks = marks1 + marks2;
        System.out.println("Name is " + name + " and total marks are " + totalMarks);
    }
}

Sample output

Enter name: Ram
Enter marks in first subject: 80
Enter marks in second subject: 90
Name is Ram and total marks are 170

 

answered by Ranjith (2,683 points)
...