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

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









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???
program is not running in Eclipse.... - WebSevices
C++ program not running
process of compiling and running java program
why the program is showing error?
arrays program - Java Interview Questions
Java Program MY NAME
My first Java Program
program that uses while loops to perform the following steps :
ModuleNotFoundError: No module named 'loop1'
ModuleNotFoundError: No module named 'loopa'
ModuleNotFoundError: No module named 'loopa'
write program have product - using loops
why java program not run with msword editor
My first struts 2 program
details of my program - Java Beginners
Arrays, loops and string handling
Problem in running first hibernate program.... - Hibernate
Compiling and Running Java program from command line
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
Program
Program
program
program
program
program
program
program
ModuleNotFoundError: No module named 'my_print_haha_program'
I need add my java program with a picture.
java program for me to see who are on my server

Ads