Forums Register Login

help on input character into screen

+Pie Number of slices to send: Send
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);
}
}

------------------------------
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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 ]
+Pie Number of slices to send: Send
 

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.
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1483 times.
Similar Threads
help with arrays program in java
diamond pattern without parse.int (Someone help me T.T) :cry:
variable counter might not have been initialized
Need help writing star pattern to file
Using Nested For Loops To Make Triangle
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:56:07.