Arrays case

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • himal
    New Member
    • May 2020
    • 1

    Arrays case

    please help me....
    1.Why doesn't this run?
    2.When the user makes the first input and asks if the data needs
    to be inserted again, why doesn't it run again?
    3.How to make array size dynamic data types?[/B]
    Attached Files
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    The while loop has no body because of the semicolon.

    Comment

    • Ishan Shah
      New Member
      • Jan 2020
      • 47

      #3
      Using the following code your program will work as per your requirements :

      Code:
      import java.util.*;
      class Example
      {
      	public static void main(String args[])
      	{
      		Scanner input=new Scanner(System.in);
      	                     int[] x=new int[4];
                           	String[] y=new String[5];
                           	char r;
      		System.out.print("How Many Student Detail Do you want Enter  :");
      	                     int count=Integer.parseInt(input.nextLine());
      		for(int i=1;i<=count;i++)
      		{
                           		System.out.print("Enter student ID :");
      	                     	x[i]=Integer.parseInt(input.nextLine());
      		                     System.out.print("Enter student Name :");
                           	                     y[i]=input.nextLine();
                                                	
      		 }	
      		
      	                 	do 
      		{
      			System.out.print("Student has been added successfully.Do you want to add a new student (y/n) :");
      		                     r = input.next().charAt(0);
      			count=1;  
      			System.out.print("Enter student ID :");
      	                     	x[count]=Integer.parseInt(input.nextLine());
      		                     System.out.print("Enter student Name :");
                           	                     y[count]=input.nextLine();
      			
      	                     } while (r == 'y');
      							  
      	}
      }

      Comment

      Working...