Current location: Hot Scripts Forums » Programming Languages » Everything Java » Solve this java problem for me ,thanks


Solve this java problem for me ,thanks

Reply
  #1 (permalink)  
Old 08-19-04, 11:02 PM
overule overule is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Cool Solve this java problem for me ,thanks

Design, write in Java, test and document a program (application) that accepts a short (i.e. less
than 20 character) string from the user and prints it out on the screen in a certain pattern. In
response to the user keeping pressing enter, the program moves it across the page to bounce off
column 20 and return. Then the program terminates. Use “*” characters to fill in the unused
columns.
For example, suppose that the user enters “dipsy”. Here is the output; each line of output is in
response to the user pressing the “enter” key.
Please enter your string: dipsy
dipsy**************
*dipsy*************
**dipsy************
***dipsy***********
...etc ...
*************dipsy*
**************dipsy
*************dipsy*
************dipsy**
...etc...
*dipsy*************
dipsy**************
Program terminated.
__________________
<p><font size="2"><b>http://www.overule.net<br>
<font color="#FF0000">
Web Hosting- Serving At The Best!</font></b></font><b><font color="#FF0000">
<br></font><font size="2">Unlimited features</font>
<br></b><font size="2" color="#FF0000"><b>: :RESELLERS: :SHARED HOSTING: : EMAIL HOSTING: : DESIGN: :</b></font>
Reply With Quote
  #2 (permalink)  
Old 08-21-04, 05:20 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Well i did it on a TI-83 but that's not in java....
Reply With Quote
  #3 (permalink)  
Old 08-22-04, 07:34 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Except on a Ti-83 you can only fit 16 characters across
Reply With Quote
  #4 (permalink)  
Old 12-09-04, 10:06 AM
jonassala's Avatar
jonassala jonassala is offline
New Member
 
Join Date: Dec 2004
Location: Sweden
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Post

Code:
import java.io.*;

public class Twenty
{
    
    private static final String A = "********************";
    private static final int MAX_CHAR = A.length();;
    
    public static void main(String[] args)
	throws IOException
    {
	// Read input.

	BufferedReader in =
	    new BufferedReader(new InputStreamReader(System.in));
	String input = "";

	// Skip empty lines.
	
	while (input.length() == 0)
	{
	    input = in.readLine();
	}

	// The size of the input string.
	
	int s = input.length();

	// Validate the length.
	
	if (s >= MAX_CHAR)
	{
	    System.out.println("Text must be less than " + MAX_CHAR + " characters.");
	    return;
	}

	// Asterisks in a single line.

	int total = MAX_CHAR - s;
	
	// Do the printout.
	
	for (int i = 0; i < 2 * total + 1; i++)
	{
	    // Asterisks last.
	    // The distance between total and current line number.

	    int last = Math.abs(total - i);

	    // Asterisks first.
	    // The remaining asterisks.
	    
	    int first = total - last;

	    // Print one line.
	    
	    System.out.println(A.substring(0, first) +
			       input +
			       A.substring(0, last));
	}
	System.out.println("Program terminated.");
    }
}
Reply With Quote
  #5 (permalink)  
Old 12-09-04, 01:38 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Would be nice to have the program ask for your input. Here is the same thing with two lines added to prompt user for input. I also compiled it, for those who don't have a java compiler.


Code:
 
import java.io.*;
public class Twenty2
{
	
	private static final String A = "********************";
	private static final int MAX_CHAR = A.length();;
	
	public static void main(String[] args)
 throws IOException
	{
		// Ask User for Input
 System.out.println("\nEnter Your Input Here: \n");
		// Read input.
 BufferedReader in =
	 new BufferedReader(new InputStreamReader(System.in));
 String input = "";
 // Skip empty lines.
 
 while (input.length() == 0)
 {
	 input = in.readLine();
 }
 // The size of the input string.
 
 int s = input.length();
 // Validate the length.
 
// Extra empty line for clarity 
System.out.println("\n");
 
 if (s >= MAX_CHAR)
 {
	 System.out.println("Text must be less than " + MAX_CHAR + " characters.");
	 return;
 }
 // Asterisks in a single line.
 int total = MAX_CHAR - s;
 
 // Do the printout.
 
 for (int i = 0; i < 2 * total + 1; i++)
 {
	 // Asterisks last.
	 // The distance between total and current line number.
	 int last = Math.abs(total - i);
	 // Asterisks first.
	 // The remaining asterisks.
	 
	 int first = total - last;
	 // Print one line.
	 
	 System.out.println(A.substring(0, first) +
		  input +
		  A.substring(0, last));
 }
 System.out.println("Program terminated.");
	}
}
Attached Files
File Type: zip Twenty2.zip (1.7 KB, 183 views)
__________________
Reply With Quote
  #6 (permalink)  
Old 12-10-04, 01:02 AM
jonassala's Avatar
jonassala jonassala is offline
New Member
 
Join Date: Dec 2004
Location: Sweden
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hey, I'm a server side programmer, I don't bother with user friendlyness ;-)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
Help Java Script problem in ASP Sim JavaScript 1 08-11-04 10:16 AM
Problem: Php with java!?! 1jetsam PHP 3 04-18-04 10:12 AM
Problem with java links Kingfishsj JavaScript 0 08-01-03 08:09 AM


All times are GMT -5. The time now is 05:28 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.