|
-
Jul 23rd, 2003, 04:17 AM
#1
Thread Starter
New Member
Simple java program
I'm beginner in java . now i try to write a simple program to keep the friends particulars and relative particulars.
on the screen will display the following information:
1. friends information
2. relative information
Please enter your selection :
Now, my problems are how do write the code to read the selection from the user. for example user key in "1" then the friend information screen will be appear.
second, how to clear screen in dos.
-
Jul 23rd, 2003, 12:58 PM
#2
There is no proper screen clearing. Simply output a lot of (~24) newlines (standard console height is 24 lines).
For all other questions:
http://java.sun.com/
has great tutorials.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 23rd, 2003, 01:31 PM
#3
Dazed Member
Any console programs can get information from the user in one of two ways. Either by accessing the information stored in the args String[] array or by using Streams. The first block of code just prints out the arguements passed in on the command line. The second block of code uses a combination of different streams to obatin the user input.
Code:
public class C{
public static void main(String[] args){
for(int i = 0; i < args.length; i++){
System.out.println(args[i]);
}
}
}
Code:
import java.io.*;
public class C{
public static void main(String[] args){
try{
System.out.println("Enter data to be echoed");
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
String s = buff.readLine();
System.out.println(s);
}catch(IOException e){System.err.println(e);}
}
}
-
Jul 23rd, 2003, 11:47 PM
#4
Thread Starter
New Member
Thanks Dilenger4!
now i continue write some code and some errors come out:
mport java.io.*;
public class Assignment {
public static void main (String args []) {
try{
System.out.println(" Welcome to the Friendship CLUB\n\n");
System.out.println("1. Friend\n");
System.out.println("2. Relative\n");
System.out.println(" Please Enter your Selection:" );
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
String sel = buff.readLine();
System.out.println(sel);
}catch(IOException e){System.err.println(e);}
If (sel = 1)
{
try{
System.out.println(" Friend Information\n\n");
System.out.println(" Friend Name : ");
System.out.println(" Friend address: ");
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
String name = buff.readLine(); String add = buff.readLine();
System.out.println(name);
System.out.println(add);
}catch(IOException e){System.err.println(e);}
} else
{System.out.println(" Sale\n\n");}
}
My Questions are:
1) Why String sel does not accept 1?
2) am I right in my code?
-
Jul 23rd, 2003, 11:57 PM
#5
Dazed Member
Taking a quick look at your code you are using the assignment opperator in your if() statement. It should look like this if(sel.equals("1"))
-
Jul 24th, 2003, 04:17 AM
#6
Thread Starter
New Member
I had change If (sel.equal("1")), but compiler could not resolve the symbol
Last edited by bonboncat; Jul 24th, 2003 at 04:35 AM.
-
Jul 24th, 2003, 05:14 AM
#7
Java is case sensitive, it's if, not If.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|