Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:22:52+00:00 2026-06-15T16:22:52+00:00

My Question probably does not explain the issue well at all but what I’m

  • 0

My Question probably does not explain the issue well at all but what I’m experiencing is that I’m able to get the first line of a string for a “box” as shown in the sample here: https://docs.google.com/open?id=0B_ifaCiEZgtcVUx3c2c1VWs2NEE

here’s my main code as it is now:

import java.util.Scanner;
import static java.lang.System.*;

public class LineBreaker
{
 private String line;
 private int breaker;

public LineBreaker()
{
this("",0);
}

 public LineBreaker(String s, int b)
  {
   line = s;
   breaker = b;
  }

public void setLineBreaker(String s, int b)
{
    line = s;
    breaker = b;
}

public String getLine()
{
    return line;
}

public String getLineBreaker()
{
    String box ="";
    Scanner scan = new Scanner(line);
    //scan.useRadix(breaker);
    //while (scan.hasNext()){
        for(int i = 0; i < breaker; i++){
        box += scan.next();

    }box += "\n";
    //}

    return box;
}

public String toString()
{
    return line + "\n" + getLineBreaker();
}
}

And it’s associated runner class:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;

public class Lab12f
 {
  public static void main(String args[]) throws IOException
  {
   LineBreaker test = new LineBreaker("1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9", 4);
    out.println(test);

    test.setLineBreaker("t h e b i g b a d w o l f h a d b i g e a r s a n d t e e t h", 2);
    out.println(test);

    test.setLineBreaker("a c o m p u t e r s c i e n c e p r o g r a m", 7);
    out.println(test  );

    test.setLineBreaker("i a m s a m i a m", 2);
    out.println(test);

}
}

currently my output is looking like this:

1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

1234

t h e b i g b a d w o l f h a d b i g e a r s a n d t e e t h

th

a c o m p u t e r s c i e n c e p r o g r a m

acomput

i a m s a m i a m

ia

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:22:53+00:00Added an answer on June 15, 2026 at 4:22 pm

    Your issue is in this block of code here:

    public String getLineBreaker() {
      String box ="";
      Scanner scan = new Scanner(line);
      //scan.useRadix(breaker);
      //while (scan.hasNext()){
          for(int i = 0; i < breaker; i++){
          box += scan.next();
      
      }box += "\n";
      //}
    }
    

    You never tell the program to keep reading from the line after reading to the first break.

    EDIT

    Ok. Don’t use scan.useRadix(breaker). That doesn’t apply–useRadix() tells the compiler what base to parse numbers in.

    You were on the right track with the while loop. If you uncomment it, though, it throws an error. This is when the scanner is looking for the next element in the line, but there isn’t one. Check if there’s an element remaining before reading it…

    And a tip from personal experience: Meeting with your professor when you have a question can make a world of difference… This is a place to ask questions (I’m not saying you are wrong to do so), but I will say that your professor knows you better than I do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question is probably not the best one to describe my issue but I
My question is probably not well phrased and it's probably a dupe but here
This question has probably been asked before, but I am not able to find
Let me first say that I realize this question is vague and does not
Probably a trivial question, but in which order does Exception::getTrace return calls? Most recent
I realize this question has probably been asked numerous times, but I have not
All, This question probably has a very simple answer - something I'm overlooking. But
First, excuse me please, this is not a programming question, but I think it
I realize my title probably doesnt explain my situation very well, but I honestly
So, this question is probably fairly stupid, but I'm not too familiar with Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.