please explain this prog

Ads
 

please explain this prog

import java.io.*;
class Studar{
   public static void main(String ar[]) throws IOException {
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("how many subjects");
int n= Integer.parseInt(br.readLine());
//create array for marks
int marks[]=new int[n];
int tot=0;
for(int i=0;i<n;i++){
System.out.println("enter marks:\n");
marks[i]=Integer.parseInt(br.readLine());
}
for(int i=0;i<n;i++){
tot=tot+marks[i];}
System.out.println("tot marks="+tot);

float percent= (float)tot/n;

System.out.println("percentage="+percent);
}
}
View Answers

January 18, 2011 at 11:54 AM

Hi Friend,

import java.io.*;
class Studar{
    public static void main(String ar[]) throws IOException { 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("how many subjects");
        int n= Integer.parseInt(br.readLine()); 
        int marks[]=new int[n];
        int tot=0;
        System.out.println("Enter marks of "+n+" subjects: ");
        for(int i=0;i<marks.length;i++){
            int m=Integer.parseInt(br.readLine());
            marks[i]=m;
            tot+=marks[i];
        }
        System.out.println("Total Marks: "+tot);
    }
}

The given code reads the number of subjects from the console and according create an array in order to store the marks of each subject and calculate the total marks.

The InputStreamReader(System.in) allow the user to input and the method readLine() of BufferedReader class read the number of subjects from the console. By using the Integer.parseInt(), the no of subject get converted into number. An array is created to store the marks of each subject whose length is the number of subjects. The method Integer.parseInt(br.readLine()), reads the marks of each subject eneterd by user. A variable tot is defined to store the sum of all the marks.

Thanks

Ads









Related Tutorials/Questions & Answers:
please explain this prog
please explain this prog  can u explain this import java.io.*; class SString{ public static void main(String ar[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in
please explain this prog
please explain this prog  import java.io.*; class Studar{ public static void main(String ar[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("how many
Advertisements
please help me in these prog
please help me in these prog   create 2 jdbc programs including awt create 2 jdbc programs including swing create 2 jdbc programs including command line argument create 2 jdbc programs including io class 4 jdbc prog using
please explain this program
please explain this program  public class MainClass { public static void main(String[] args) { System.out.println("Java
Please explain @interface with an example
Please explain @interface with an example  Here is the code snippet...) private Runnable runnable; where Runnable is an interface. Could you please explain what does all these mean? How all these work
Please explain @interface with an example
Please explain @interface with an example  Here is the code snippet: @Retention(RUNTIME) @Target({ FIELD }) public @interface InjectProperty... runnable; where Runnable is an interface. Could you please explain what does
Please explain Hibernate Sessionfactory.
Please explain Hibernate Sessionfactory.  Hi there, Please explain Hibernate session factory in detail. I have just started learning hibernate so i..., the tutorials here will help you learn Hibernate and will explain about hibernate
Please explain the logic....
Please explain the logic....  class A1 { } class B extends A1 { } public class ComingThru { static String s = "-"; public static void main(String[] args) { A1[] aa = new A1[2]; B[] ba = new B[2
Please explain me the flow of this program..
Please explain me the flow of this program..  // Substring replacement. class StringReplace { public static void main(String args[]) { String org = "This is a test. This is, too."; String search
please explain me the flow of this program
please explain me the flow of this program  class Bticket extends Thread { Object train,comp; Bticket(Object train,Object comp){ this.train=train; this.comp=comp; } public void run(){ synchronized
Please explain what is hibernatetemplate with an example code.
Please explain what is hibernatetemplate with an example code.  hi, Please explain Hibernate template example code to me..   Hello Friend... is org.springframework.orm.hibernate.HibernateTemplate Please follow the given link for more details: hibernateTemplate
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss  Question: We are given an array of 2n integers wherein each pair in this array of integers represents the year of birth and the year of death
403 Forbidden error - What is 403 Forbidden error, please explain...
403 Forbidden error - What is 403 Forbidden error, please explain...  Can anyone please explain, What is 403 Forbidden error. And how can i remove this error, which is restricting my page from loading it. Thanks!!   Hi
In tag files,does attribute values accept expressions or not? If not please explain the reason
.... could any body explain this please............** HTTP Status 500 - type...In tag files,does attribute values accept expressions or not? If not please explain the reason  **Actually when i do manually in tomcat server
403 Forbidden error - What is 403 Forbidden error, please explain...
403 Forbidden error - What is 403 Forbidden error, please explain...  Can anyone please explain, What is 403 Forbidden error. And how can i remove this error, which is restricting my page from loading it. Thanks!!   Ok
Please explain this code as many packages and classes are unknown to me .!
Please explain this code as many packages and classes are unknown to me .!  print("code sample");package bluetooth; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.obex.ClientSession; import
question "writing prog"
question "writing prog"  Hello I want helping for this question, please Write a program that reads some friendsā?? names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
NEED A PROG
NEED A PROG   whats the program to add,delete, display elements of an object using collecions. without using linked list   Hi Friend, Try the following code: import java.util.*; class CollectionExample { public
turbo C prog.
turbo C prog.  Is is possible print ASCII value of a alphabets using turbo C prog
ModuleNotFoundError: No module named 'prog'
ModuleNotFoundError: No module named 'prog'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'prog' How to remove the ModuleNotFoundError: No module named 'prog' error
turbo C prog. Q3
turbo C prog. Q3  What is the difference between if and ladder if ? Describe ladder if with example. What is the purpose of the parameter passing ? please Describe with example.   if statement is used to write
java prog que
java prog que  create a class that returns the reverse of each word in the given string. For example if we give "who are u?" as input, it should return "ohw era u
Solution to C prog
Solution to C prog   Hi, Pls any body help, why the following prog crashing while running. #include<stdio.h> #include<conio.h> int main(){ int n,*fact(int *n); printf("Enter the number:"); scanf
ModuleNotFoundError: No module named 'func_prog'
ModuleNotFoundError: No module named 'func_prog'  Hi, My Python... 'func_prog' How to remove the ModuleNotFoundError: No module named 'func_prog' error? Thanks   Hi, In your python environment you
make a prog for this query
make a prog for this query  write a program implementing interface for personal data n salary details. interface must contain abstract methods. steps for the program are 1) store the data in text file 2)display salary when emp id
turbo C prog.
turbo C prog.  Is it possible to print ASCII value A to Z with out using scan ? also give to simple example of binary search ...   #include<stdio.h> #include<conio.h> void main() { for(char c='A';c<
(ForPro) turbo C prog. Q4
(ForPro) turbo C prog. Q4  I need to learn some easy foxpro program.. for example sum,interchange, loop etc
Java entry prog.
Java entry prog.  Dear sir I will enter the dept code, dept name and insert into dept_mast and save. Pl. Dept_mast Dept_code Char(2) Primary key (no duplicate key allowed) Dept_name Char(25
Explain various access modifiers and their visibility.
Explain various access modifiers and their visibility.  Explain various access modifiers and their visibility.   Please visit the following link: Java Access Modifiers
explain this method
explain this method   i hope any one can explain this method ` private void showMonth(int m, int y) { int lead_spaces = 0; if (m &lt; 0 || m > 11) { System.out.println("It should be 1 to 12
Explain Hibernate Relationships with example.
Explain Hibernate Relationships with example.  Hello, Please explain various hibernate relationships. And if you can provide some examples that would be a great help.. Thank you....   Hi, Hibernate relational

Ads