本文介绍了我需要通过使用scanner类来通过用户输入访问名称和ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package customer_details;
import java.util.*;
public class customer_deatils
{
	
	public String name;
	public int id;
	
	public customer_deatils(String name,int id)
	{
		this.name=name;
		this.id=id;
	}
	public static void    customer_deatils(customer_deatils[] c)
	{
		for(customer_deatils d:c)
		{
			System.out.println(d);
		}
		
	}
	public String toString()
	{
		return name+" "+id;
	}
	public static void main(String args[])
	
	{
		Scanner s1=new Scanner(System.in);
		customer_deatils []acc1=new customer_deatils[3];
	//	customer_deatils obj=new customer_deatils(s1.nextLine(),s1.nextInt());
		
		 for(int i=0;i<acc1.length;i++)
		 {
			 
			 acc1[i]=new customer_deatils(s1.nextLine(),s1.nextInt());
			 
			 
		 }
		customer_deatils(acc1);
		
		
		
		
		
	}
	
	
}





我尝试了什么:



i尝试了但它显示错误输入不匹配,但我是根据构造函数中的数据类型给出输入



What I have tried:

i tried but it shows error input mismatch, but i am giving input based on the datatype in constructor

推荐答案


这篇关于我需要通过使用scanner类来通过用户输入访问名称和ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:42