answersLogoWhite

0


Best Answer

// set up reader

BufferedReader reader = new BufferedReader(new InputStreamReader(

System.in));

// number of line to read

int numberOfLines = 3;

// initialize the counter for number of characters

int numberOfChars = 0;

// prompt user to enter the lines of text

System.out.format("Enter %d lines of text:\n", numberOfLines);

for (int i = 0; i < numberOfLines; i++) {

String line = reader.readLine();

// increment the counter with the number of characters entered in current line

numberOfChars += line.length();

}

// print the number of characters entered

System.out.println("Number of characters entered: " + numberOfChars);

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java Program requests and reads three lines of text and output the total number of characters entered sample code?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What does cout stand for in c?

It serves to send usually text-based information on the monitor (in currently running application, window), for instance:...int myVariable;cout >> "Please enter a number: ";cin >> myVarible;//You entered number 5cout


C program to find square of an integer?

#include#includevoid main(){long int n;printf("Please enter the number");scanf("%ld" ,&n);n=n*n;printf("Square of entered number = %ld ");}but if you want to show the entered number e.g.Square of the entered number 8=64then below is the code.#include#includevoid main(){long int m,n;printf("Please enter the number");scanf("%ld" ,&n);m=n;n=n*n;printf("Square of entered number %ld = %ld ",m,n);}


Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.


How to write a java program to extract the last digit from the input?

Assuming you've entered a multi-digit number whole number (an integer), then take the modus (%) of the number and 10. E.g., if the number input was 1234, then 1234 % 10 is 4. Thus the final digit is 4. Note that modus 10 is the same as dividing the number by 10 and taking the remainder.


How do you Write a java program to find the average of given numbers?

import java.util.Scanner; public class Numbers { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int max = -100; int min = 100; int sum = 0; System.out.println("Enter ten integers"); for(int i = 0; i &lt; 10; i++) { int input = scan.nextInt(); if(input &gt; max)//test if the number entered is larger than any previous number max = input; if(input &lt; min)//test if the number entered is smaller than any previous number min = input; sum += input;//add the input to the sum } System.out.println("The maximum number entered is: " + max + "\nThe minimum number entered is: " + min + "\nThe average of the numbers is: " + (sum / 10));//prints out the results } }

Related questions

Write a shell program to find given no is even or odd?

The pseudo code would be as follows (you figure out the syntax) 1) Prompt the user to enter a number 2) If entered number is alpha, quit program after displaying message that the user ended the program. 3) Otherwise, find Modulo 2 of the entered number. This is a fancy way of saying "find the remainder when the number is divided by 2) 4) If Modulo 2 is zero, the number is even, otherwise odd 5) Display message showing if the entered number was Even or Odd 6) Branch back to step 1


What is c program to calculate product of all even numbers from entered number down to 1?

c is programming laungage


What does API stand for in Twhirl?

Application Programming Interface, or how the program interacts with the Twitter service. You're limited to a set number of requests per hour (these happen when you submit a tweet, or you receive new tweets). Twhirl will automatically manage the API requests for you.


What characters are not allowed in Microsoft Excel?

I am not aware of any characters that are not allowed to be entered into an excel cell. However, there are some special rules about characters. You can not use spaces in macro or range names. You can not use a number as the first character in a range name.


What does cout stand for in c?

It serves to send usually text-based information on the monitor (in currently running application, window), for instance:...int myVariable;cout >> "Please enter a number: ";cin >> myVarible;//You entered number 5cout


What is a number that can be entered into a cell on Excel?

Which of the following is a number that can be entered into a cell?


Writa a program to print a number in word eg if 972 is entered through the keyboard that should print nine seven two?

nine seven two


C program to find square of an integer?

#include#includevoid main(){long int n;printf("Please enter the number");scanf("%ld" ,&n);n=n*n;printf("Square of entered number = %ld ");}but if you want to show the entered number e.g.Square of the entered number 8=64then below is the code.#include#includevoid main(){long int m,n;printf("Please enter the number");scanf("%ld" ,&n);m=n;n=n*n;printf("Square of entered number %ld = %ld ",m,n);}


Program to count the number of characters and words in the line?

in linux wc -l filename will count the lines and wc will count the letters


What is the name of the computer program used in kindergarten and elementary school to learn Math and English where the characters were aliens?

The program is called Number Munchers and teaches addition, subtraction, multiplication, division, basic number theory, factoring and other arithmetic topics.


Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.


What number was Kentucky when it entered the country?

Number fifteen.