222k views
5 votes
A variable c of type char has been declared. Write the necessary code to read in the next character from standard input and store it in c, regardless of whether is a whitespace character.

User Blj
by
5.3k points

1 Answer

2 votes

Answer:

import java.util.Scanner;

public class num3 {

public static void main(String[] args) {

char c;

Scanner in = new Scanner(System.in);

c = in.nextLine().charAt(0);

}

}

Step-by-step explanation:

  1. Using Java Programming language.
  2. Variable c of type char is declared
  3. Scanner class is imported to receive user input
  4. the string method nextLine is used to read an entire line including whitespace
  5. charAt(0) returns the first character which is assigned to c
User Supamaze
by
4.7k points