File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help on input character into screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help on input character into screen" Watch "help on input character into screen" New topic
Author

help on input character into screen

xiao sean
Ranch Hand

Joined: Aug 20, 2007
Posts: 44
guys, sorry again. i need some help here.

1) i trying to input a letter H into the keyboard, but i return a error of

null (until.scanner),

2) i'm trying to input a character into the screen. the screen is not executing.

try to debug it but unable to.
-------------
import java.util.Scanner;
class Q4
{
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
System.out.print("Enter character that you want to print:");
int x=sc.nextInt();

for (int i=1;i<=5;i++)
{
for (int j=1;j<=5;j++)
{
if (i!=3){
if (j==1 || j==5){
System.out.print("*");
}
else {
System.out.print("^");
}
}
else {
System.out.print("*");
}
}// j loop
System.out.println();
} // i loop
}
}
------------


q2

-----------

import java.util.Scanner;
class KeyBoard
{
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
String x = sc.next();
char y= x.charAt(0);

System.out.print(" The characeter is: " +y);
}
}

------------------------------
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by xiao sean:
...1) i trying to input a letter H into the keyboard, but i return a error of

null (until.scanner)...

I'm not familiar with that error, and I can't reproduce it. Note that the Scanner is trying to scan an int, so make sure that's what you're giving it. When I give it an int, it works fine for me (although I'm not sure what it's doing).
Originally posted by xiao sean:
...2) i'm trying to input a character into the screen. the screen is not executing...

Here again, it's working fine for me. But note that when you run this, you won't see anything on the screen until you give the Scanner some input.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
xiao sean
Ranch Hand

Joined: Aug 20, 2007
Posts: 44
Originally posted by marc weber:

Here again, it's working fine for me. But note that when you run this, you won't see anything on the screen until you give the Scanner some input.



much thanks with the 1st help. i guess i found the problem with the int.

but for qn2. i not able to see anything reason behind it is no screen is produce before i able to input any data to it..
[ August 21, 2007: Message edited by: xiao sean ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by xiao sean:
...for qn2. i not able to see anything reason behind it is no screen is produce before i able to input any data to it.

If you want something to show, you need to code it. For example, in the first program, you had a line that prompted the user for input...

But there is nothing like this in the second program, so it just waits.
 
 
subject: help on input character into screen
 
Similar Threads
Using Nested For Loops To Make Triangle
variable counter might not have been initialized
Need help writing star pattern to file
diamond pattern without parse.int (Someone help me T.T) :cry:
help with arrays program in java