Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners please explain this prog
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kalyanitokuri
please explain this prog
1 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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);
}
}

Advertisement
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



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 explain this program
please explain this program  public class MainClass { public static void main(String[] args) { System.out.println("Java
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 @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 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
servlet prog - Java Interview Questions
servlet prog  how to forward or redirect the client request from servlet to jsp? how a thread or request pass from one servlet prog to one jsp prog? is it possible of communicating from servlet to jsp prog? please explain briefly
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
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
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
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
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
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
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<
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
Prog Error - JSP-Servlet
Prog Error   Place Ad function Browse() { Advertisement Management System Create Ad State: City: Main Category: Sub Category: Title
(ForPro) turbo C prog. Q4
(ForPro) turbo C prog. Q4  I need to learn some easy foxpro program.. for example sum,interchange, loop etc
Spring Hello World prog - Spring
Spring Hello World prog  I used running the helloworld prog code... in the web.xml file, is it the reason I'm getting nullpointer exception. please...:489) at java.lang.Thread.run(Unknown Source)  Hi Friend, Please
Explain - LDAP
Explain LDAP  Any one explain about LDAP ? and also explain about JNDI what relation b/w this two
Explain ServletContext.
Explain ServletContext.  Explain ServletContext.   Hi, Here is the answer, ServletContext interface is a window for a servlet to view it?s environment. A servlet can use this interface to get information
Explain WML
Explain WML  hii, What is WML?   hello, WML stands for Wireless Markup Language. It is a simple language used to create applications for small wireless devices like mobile phones. WML is analogous to HTML
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
Advertisements
 

 

 

DMCA.com