Thread: Help please

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Help please


    Hi
    I need a help to solve my assinment, and i tried many times but i couldn't


    1. Write a Java program to read a Name,ID and marks for 5 courses. Find the Total and Average of 5 courses. Display the values of all variables.
    Hint: Use for loop to get the input for 5 marks. Donít use 5 different variables.




    but here i couldn't solve it(the red one)



    import java.util.*;
    class Ex1
    {
    public static void main(String arg[])
    {
    String name;
    int ID,mark,a,sum=0 ;
    Scanner S=new Scanner(System.in);
    System.out.println("Enter your name");
    name=S.next();
    System.out.println("Enter your ID");
    ID=S.nextInt();
    System.out.println("enter the values");
    for(int i=1;i<=5;i++)
    {
    a=S.nextInt();

    }

    }
    }





    7.Write a java program to find the square root of every number between 1 and 20.Use any loop.


    8.Consider the following expression.
    Z=a4+b3+c2+d
    Read appropriate inputs and display the output.


    And thanks
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Please edit your post and wrap the code in code tags.


    To find the total, you need to add up all the numbers that are read in. Define a variable to hold the total, initialize it to 0 and then add each number to it.
    To find the average, you need to count the number of numbers read and then divide the total by the number of numbers that were read in.

IMN logo majestic logo threadwatch logo seochat tools logo