LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2015, 05:27 AM   #1
NoWeDoR
Member
 
Registered: Jun 2015
Posts: 32

Rep: Reputation: Disabled
How to display data that got from user in Java?


Hello guys. I've written a simple program as below that gets names from user and holds them into method.

Main

Code:
import java.util.Scanner;

public class TestProject 
{
	public static void main(String[] args)
	{
		writing input = new writing();
		Scanner keyboard = new Scanner(System.in);
		
		for (int i = 0; i < 2; i++)
		{
			System.out.print("Enter a name: ");
			input.setName(keyboard.nextLine());	
		}
	}
}
Class

Code:
public class writing 
{
	String name;
	
	public void setName(String name)
	{
		this.name = name;
	}
}
Yes, I want to display these names in order outside of for loop by using method. Is it possible? If there is any way to that, can you share?
 
Old 11-05-2015, 05:43 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You could develop a getName method. Also you should use some collection to store the 'writing's
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: User data manifesto seeks to give people control of their data LXer Syndicated Linux News 0 08-30-2015 11:42 PM
Linux display(window frame) options for live webcam display: java? PoleStar Linux - Newbie 1 08-15-2012 03:49 PM
Java not working. No .java folder in /home/<user> moxieman99 Fedora 1 08-19-2009 01:47 PM
LXer: Java Data Objects and Service Data Objects in SOA LXer Syndicated Linux News 0 01-17-2009 06:10 AM
retreived data and display data upon choice from first page? ati Programming 0 05-06-2006 05:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration