Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:57:15+00:00 2026-05-29T09:57:15+00:00

I have wrote below code. import java.io.*; class Test { public static void main(String

  • 0

I have wrote below code.

import java.io.*;

class Test {

    public static void main(String args[]) throws IOException {
        DataInputStream dis = new DataInputStream(System.in);

        String name[] = new String[10];
        float s1[] = new float[10];
        float s2[] = new float[10];
        float s3[] = new float[10];
        float s4[] = new float[10];
        float tot[] = new float[10];
        float avrg[] = new float[10];

        float total = 0;
        float avg = 0;

        for (int i = 0; i < 2; i++) {
            total = 0;
            avg = 0;

            System.out.println("Enter Name : ");
            String j = dis.readLine();
            name[i] = j;


            System.out.println("Enter Mark1 : ");
            String y = dis.readLine();
            float x = Float.parseFloat(y);
            s1[i] = x;

            System.out.println("Enter Mark2 : ");
            String n = dis.readLine();
            float m = Float.parseFloat(n);
            s2[i] = m;

            System.out.println("Enter Mark3 : ");
            String v = dis.readLine();
            float u = Float.parseFloat(v);
            s3[i] = u;

            System.out.println("Enter Mark4 : ");
            String a = dis.readLine();
            float b = Float.parseFloat(a);
            s4[i] = b;

            total = x + m + u + b;
            tot[i] = total;
            avg = total / 4;
            avrg[i] = avg;
        }

        System.out.println();

        System.out.println("Name" + "\t" + "Sub_1" + "\t" + "Sub_2" + "\t" + "Sub_3" + "\t" + "Sub_4" + "\t" + "Total" + "\t" + "Avg" + "\t" + "Rank");
        System.out.println();

        for (int k = 0; k < 2; k++) {
            System.out.println(name[k] + "\t" + s1[k] + "\t" + s2[k] + "\t" + s3[k] + "\t" + s4[k] + "\t" + tot[k] + "\t" + avrg[k]);
        }

        System.out.println();

    }
}

Above code gave result like below.

Name    Sub_1   Sub_2   Sub_3   Sub_4   Total   Avg     Rank

A       10.0    10.0    20.0    10.0    50.0    12.5
B       20.0    20.0    30.0    10.0    80.0    20.0

Now I want get Rank by Total and print output as below.

Name    Sub_1   Sub_2   Sub_3   Sub_4   Total   Avg     Rank

A       10.0    10.0    20.0    20.0    60.0    15.0    2
B       10.0    20.0    3.0     50.0    83.0    20.75   1

How can i get Rank from Total ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:57:16+00:00Added an answer on May 29, 2026 at 9:57 am

    This will give you the result, but for sure this is not an optimised solution. I just given a working solution.

    import java.io.*;  
    
        class Test {
        public static void main(String args[]) throws IOException {
            DataInputStream dis = new DataInputStream(System.in);
            String name[] = new String[10];
            float s1[] = new float[10];
            float s2[] = new float[10];
            float s3[] = new float[10];
            float s4[] = new float[10];
            float tot[] = new float[10];
            float avrg[] = new float[10];
            float rankAvg[] = new float[10];
            int rank[] = new int[10];
            float total = 0;
            float avg = 0;
    
            for (int i = 0; i < 4; i++) {
    
                total = 0;
                avg = 0;
                System.out.println("Enter Name : ");
                String j = dis.readLine();
                name[i] = j;
                System.out.println("Enter Mark1 : ");
                String y = dis.readLine();
                float x = Float.parseFloat(y);
                s1[i] = x;
                System.out.println("Enter Mark2 : ");
                String n = dis.readLine();
                float m = Float.parseFloat(n);
                s2[i] = m;
                System.out.println("Enter Mark3 : ");
                String v = dis.readLine();
                float u = Float.parseFloat(v);
                s3[i] = u;
                System.out.println("Enter Mark4 : ");
                String a = dis.readLine();
                float b = Float.parseFloat(a);
                s4[i] = b;
                total = x + m + u + b;
                tot[i] = total;
                avg = total / 4;
                avrg[i] = avg;
                rankAvg[i]= avrg[i];
            }
    
            for(int i=0; i<4; i++){
    
                for(int j=i+1;j<4;j++){
    
                    if(rankAvg[i] < rankAvg[j]){
                        float t = rankAvg[j];
                        rankAvg[j] = rankAvg[i];
                        rankAvg[i] = t;
                    }
    
                }
            }
    
            System.out.println();
            System.out.println("Name" + "\t" + "Sub_1" + "\t" + "Sub_2" + "\t" + "Sub_3" + "\t" + "Sub_4" + "\t" + "Total" + "\t" + "Avg" + "\t" + "Rank");
            System.out.println();
    
            for (int k = 0; k < 4; k++) {
    
                System.out.println(name[k] + "\t" + s1[k] + "\t" + s2[k] + "\t" + s3[k] + "\t" + s4[k] + "\t" + tot[k] + "\t" + avrg[k] + "\t" + findRank(avrg, rankAvg, k));
            }
    
            System.out.println();
        }
    
        public static int findRank(float[] avrg, float[] rankAvg, int k){
            int rank=0;
            for(int i=0; i<4; i++){
                if(avrg[k] == rankAvg[i]){
                    rank=i+1;
                }
            }
            return rank;
        }
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Parent class is : import java.io.IOException; public class Parent { int x =
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote the beautiful python example code below. Now how do I make it
I have a class that reads the state of what string is in a
I have a client/server program and applet. I will show the code below. Can
I wanted to validate the below test I wrote to validate the fact that
I am trying to upload files using Java URL class and I have found
In trying to write more testable Java code, I have been using the Model-View-Presenter
I have a nice java code that unzips a .zip file. But problem with
I have wrote a code that can read an excel 2007 file using Microsoft

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.