Why is my program running an infinite loop? Parallel Arrays Program

Ads
 

Why is my program running an infinite loop? Parallel Arrays Program

Calculate and print the average (this works) Search for Joel in the list, print his data----for some reason this is outputting the wrong data and is outputting an infinite loop. Why? import java.util.*; import java.text.DecimalFormat; public class parallel { public static void main (String[]args) { Scanner input=new Scanner (System.in); DecimalFormat fmt=new DecimalFormat ("0.##"); double[]gpa=new double [5]; String[]name=new String [5]; int[]id=new int [5]; double avg=0.0; double sum=0.0;

    for (int i=0;i<gpa.length;i++)
    {
        System.out.println("Enter a name: ");
        name[i]=input.nextLine();
        System.out.println("Enter GPA: ");
        gpa[i]=input.nextDouble();
        System.out.println("Enter ID: ");
        id[i]=input.nextInt();
        input.nextLine();
    }

    for (int i=0;i<name.length;i++)
    {

        System.out.println("Name: "+name[i]+ " id: "+id[i]+ " gpa: "+gpa[i]);        
    }
    for (int i=0;i<gpa.length;i++)
    {
    sum=sum+gpa[i];    
    }
    avg=sum/gpa.length;
    System.out.println(fmt.format(avg));

    System.out.println("Enter a name to search: ");
    String enter=input.nextLine();
    int i=0;
    boolean found=false;
    do{
        if (name[i].equals(enter))
            found=true;

            System.out.println(id[i]);
            System.out.println(gpa[i]);
        }while (i<enter.length()&&!found);

}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
Why is my program running an infinite loop? Parallel Arrays Program
About running the Applet Program
Advertisements
About running the Applet Program
Running core java program
Java is an opensource program or not? why???
C++ program not running
process of compiling and running java program
why the program is showing error?
program that uses while loops to perform the following steps :
Java Program MY NAME
My first Java Program
Arrays, loops and string handling
why java program not run with msword editor
My first struts 2 program
ModuleNotFoundError: No module named 'loop1'
Compiling and Running Java program from command line
program
program
program
program
program
program
program
program
program
Program
Program
program
program
program
program

Ads