Results 1 to 3 of 3

Thread: small problem

  1. #1
    rawan is offline Member
    Join Date
    Dec 2009
    Posts
    7
    Rep Power
    0

    Default small problem

    hiii

    i have small problem in my code
    if i want to input more than 6 charactars it will repet the character before the last one
    and i didn't want it to repet it


    2. Write a program that reads a string composed of more than 3 characters. Your program then generates and prints three new strings that are the first, second and third parts of the original string.

    this is ma code

    import java.util.*;

    public class Sheet5Q2
    {
    public static void main(String [] args)
    {

    Scanner console = new Scanner (System.in);

    String s,s1,s2,s3;

    System.out.println("Enter string composed of more than 3 characters:");
    s = console.next();

    s1 = s.substring(0, s.length()/2);
    s2 = s.substring(s1.length(), s.length()-1);
    s3 = s.substring( s.length()-1, s.length());

    System.out.println(s1);
    System.out.println(s2);
    System.out.println(s3);

    }}
    Last edited by rawan; 04-03-2010 at 10:50 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    you mean you don't want to input twice?

    So modify your code like a

    Java Code:
    public static void main(String [] args)
    {
    
    
    String s,s1,s2,s3;
    
    System.out.println("Enter string composed of more than 3 characters:");
    Scanner console = new Scanner (System.in);

Similar Threads

  1. Replies: 13
    Last Post: 02-20-2010, 08:56 PM
  2. Small problem with Stacks
    By SMHouston in forum New To Java
    Replies: 13
    Last Post: 10-16-2009, 03:34 AM
  3. small problem
    By barusk in forum Networking
    Replies: 4
    Last Post: 03-21-2009, 07:19 AM
  4. small problem in connection
    By BsBs in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-27-2009, 07:03 AM
  5. Small problem
    By ayoood in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 01:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •