02-5-2007, 02:39 PM | #1 |
Banned
Join Date: Dec 2006
Posts: 82
|
Need some help with java
Alright, I'm doing the program that asks for the length and height of a box. That part I got. What I can't seem to get is the part where it asks for an input by the user of which character to use when creating the box. Here's the code. Please help.
EDIT: Cleaner code. Code:
import java.util.Scanner; import java.lang.*; /** * Michael Cuiffi * Period 8 * 2/1/07 **/ public class DrawBox { public static void drawBox(int length, int height, String mark) { for (int i = 1; i <= height; i++){ drawBar(length, mark); } System.out.println(); } public static void drawBar(int length, String mark) { for (int i = 1; i <= length; i++) { System.out.print(mark); } System.out.println(); } public static void main(String[] args) { int length, height; String mark; String choice; Scanner s = new Scanner(System.in); System.out.print("Please enter the box's length: "); length = s.nextInt(); System.out.print("Please enter the box's height: "); height = s.nextInt(); System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): "); choice = s.nextLine(); System.out.println(); if (choice != "Y") { drawBox(length, height, "*"); } else if (choice == "Y") { System.out.print("Please enter the character: "); mark = s.nextLine(); drawBox(length, height, mark); } } } Last edited by inevitabledarkness; 02-5-2007 at 03:03 PM.. |
03-10-2007, 05:30 PM | #2 |
FFR Player
|
Re: Need some help with java
Hrm, what you want to use is an InputBox, most probably. I'm not really familiar with Java, but I'll do some research and edit this post when I find something out.
|
03-11-2007, 03:45 PM | #3 | |
FFR Player
Join Date: Jun 2006
Location: New York
Age: 32
Posts: 504
|
Re: Need some help with java
InputBox NO WAY!!! -- I hate that book AirForce CSLib UGH!
EDIT: Woops, misread. EDIT: Ok, the problem: Code:
System.out.print("Do you want to enter a character to use to display the box?\n(enter y for yes): "); choice = s.nextLine(); Quote:
Also: you might want to add if (choice != "Y" || choice !="y") to account for lowercase y's Last edited by RandomPscho; 03-11-2007 at 04:23 PM.. |
|
03-11-2007, 05:50 PM | #4 |
FFR Player
|
Re: Need some help with java
I was testing this script and was wondering why nothing was showing up, then it dawned on me, this is Java, not JavaScript, which the former happens to be my specialty. Sorry I'm of no help.
__________________
|
04-15-2007, 06:41 PM | #5 |
FFR Player
Join Date: Apr 2007
Location: New York
Posts: 27
|
Re: Need some help with java
ARGH, no, please, never use boolean with Strings. Use
Code:
choice.equalsIgnoreCase(String) Code:
if (choice.equalsIgnoreCase("Y")) System.out.println("some code..."); else if (choice.equalsIgnoreCase("N")) System.out.println("other code..."); else System.out.println("enter Y or N only!");
__________________
http://spzc.net/ Last edited by Zovistograt; 04-15-2007 at 06:42 PM.. Reason: forgot some end parentheses D: |
04-15-2007, 06:43 PM | #6 | |
FFR Player
Join Date: Apr 2007
Location: New York
Posts: 27
|
Re: Need some help with java
Quote:
__________________
http://spzc.net/ |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|