| | |
creating a method for texts
![]() |
•
•
Join Date: Nov 2007
Posts: 18
Reputation:
Solved Threads: 0
I need to creat a method something like... when the user inputs
test1
test2 haha
test3
end
and display that should contain exact same one as above except "end":
test1
test2 haha
test3
so the "end" is the keyword to finish the inputing...
oh I've just figured out. however, i see see the "end". how do i remove it?
test1
test2 haha
test3
end
and display that should contain exact same one as above except "end":
test1
test2 haha
test3
so the "end" is the keyword to finish the inputing...
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.nextLine(); s1 += s + "\n"; } System.out.println("you've typed: \n"); System.out.println(s1);
oh I've just figured out. however, i see see the "end". how do i remove it?
Last edited by enuff4life; Nov 11th, 2008 at 4:53 pm.
•
•
Join Date: Jun 2007
Posts: 59
Reputation:
Solved Threads: 3
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.next(); s1 += s+" "; // or s1 += s+"/n"; } System.out.println("you've typed: \n"); System.out.println(s1);
•
•
•
•
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.next(); s1 += s+" "; // or s1 += s+"/n"; } System.out.println("you've typed: \n"); System.out.println(s1);
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.nextLine(); if (!s.equals("end")) { s1 += s + "\n"; } } System.out.println("you've typed: \n"); System.out.println(s1);
Or keep the while-loop as it is and use the methods:
String.indexOf()
and
String.subString()
Java Syntax (Toggle Plain Text)
int index = s1.indexOf("end"); System.out.println(s1.subString(0,index));
Link for the String class.
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
•
•
That is not what enuff4life has asked. Try this:
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.nextLine(); if (!s.equals("end")) { s1 += s + "\n"; } } System.out.println("you've typed: \n"); System.out.println(s1);
Java Syntax (Toggle Plain Text)
String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); s = keyboard.nextLine(); while(!s.equals("end")){ s1 += s + "\n"; s = keyboard.nextLine(); } System.out.println("you've typed: \n"); System.out.println(s1);
![]() |
Similar Threads
- All You Need for Accessibility - Resources List (Site Layout and Usability)
Other Threads in the Java Forum
- Previous Thread: A method that returns a collection
- Next Thread: exception handling for wrong input.
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list loop map method methods mobile netbeans newbie nextline object pong print problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows






