Note that there are some explanatory texts on larger screens.

plurals
  1. POincorrect input Scanner
    primarykey
    data
    text
    <p>hey i am trying to take inputs from user one by one but its appears to take wrong input... it actually skip the one input to be taken from user .. e.g..in the code below i want to take name first then address and at last contact but when i do so it skip the name input...</p> <pre><code>import java.util.ArrayList; import java.util.Scanner; public class mainClass { public static void main(String args[]){ int value = 0; ArrayList&lt;Data&gt; Contacts = new ArrayList&lt;Data&gt;(); Scanner input = new Scanner(System.in); while(true){ System.out.println("Enter 1 to add a Contact :: Enter 2 to View all Contact"); value = input.nextInt(); switch(value){ case 1: System.out.println("Plz enter Name : "); String name = input.nextLine(); System.out.println("Plz enter Address : "); String address = input.nextLine(); System.out.println("Plz enter ContactNo : "); String contact = input.nextLine(); Data objt1 = new Data(name, address, contact); Contacts.add(objt1); break; case 2: System.out.println("Name\t\tContact\t\tAddress"); for(int i=0; i&lt;Contacts.size(); i++) { System.out.println(Contacts.get(i)); } break; default: System.out.println("Sorry wrong input"); } } } } </code></pre> <p>the data class is here</p> <pre><code>public class Data { private String name = ""; private String address = ""; private String cell = ""; public Data(String n, String a, String c){ name = n; address = a; cell = c; } public String toString() { return String.format("%s\t\t%s\t\t%s", name, cell, address); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload