• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help on input character into screen

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}

------------------------------
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
xiao sean
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic