I want to initialize the constructor which is in another class with the multiple inputs taken in for loop in the main method of another class. but the output is coming only one input. kindly solve my problem.
s1.java
import java.util.*;
public class s1 {
public static void main(String args[]) {
String name="";int roll=0;
Scanner sc=new Scanner(System.in);
for(int i=0;i<2;i++) {
name=sc.nextLine();
roll=sc.nextInt();
s2 sample=new s2(name,roll);
sample.display();
}
}
}
s2.java
public class s2 {
String name="";int roll=0;
s2(String name,int roll) {
this.name=name;
this.roll=roll;
}
void display() {
System.out.println(name+" "+roll);
}
}