Question

In: Computer Science

Define a java problem with user input, user output, Do While Statement and some mathematical computation....

Define a java problem with user input, user output, Do While Statement and some mathematical computation. Write the pseudocode, code and display output.

Solutions

Expert Solution

Here i have, provided the sum of user entered numbers using Do while loop

Pseudocode:

// initialize required variables

int sum = 0;

int num = 0;

// take user input

Scanner input = new Scanner(System.in);

// do while loop for continuos input for positive number

do {

// it will add the positive numbers

sum += num;

System.out.println("Enter positive number");

num = input.nextInt();

} while(num >= 0);

// print the sum

System.out.println("Sum is : " + sum);

Program screenshot:

Code to copy:

// required library

import java.util.Scanner;

// create a main class

class Main {

// main method

public static void main(String[] args) {

// required variables initialization

int sum = 0;

int num = 0;

// scanner class object for user input

Scanner input = new Scanner(System.in);

// do loop will iterate continuosly for positive num

do {

// addition of numbers

sum += num;

// display message

System.out.println("Enter positive number");

// take input as a number

num = input.nextInt();

// iterate for positive numbers

} while(num >= 0);

   // display sum

System.out.println("Sum is : " + sum);

input.close();

}

}


--------------------------------------------------------PLEASE UPVOTE----------------------------------------------------


Related Solutions

Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
java.. please dont change the format and give me an output sample! user need to input...
java.. please dont change the format and give me an output sample! user need to input k. public class Josephus {    /**    * All persons sit in a circle. When we go around the circle, initially starting    * from the first person, then the second person, then the third...    * we count 1,2,3,.., k-1. The next person, that is the k-th person is out.    * Then we restart the counting from the next person, go...
.......Subject Java..... main() main() will ask the user for input and then call functions to do...
.......Subject Java..... main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main(). Second function Create another function named computeBill that receives 2 parameters. It will receive the...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
Must use prompts to get input from user and alerts for output. Do not use jQuery...
Must use prompts to get input from user and alerts for output. Do not use jQuery or document.getElementById to solve these problems. User input validation is not required. Assume the user will enter correct values and write your program. Program should run once and exit. 1. Filenames: tip.html & tip.js Write a Tip program where the user enters a restaurant bill total. The program should then display two amounts: a 15 percent tip and a 20 percent tip. The output...
5. Take user input and give corresponding output. User will enter a sentence. The program will...
5. Take user input and give corresponding output. User will enter a sentence. The program will output the word that appears most frequently in this sentence. If there are multiple words with same frequency, output the first of these words. Please enter a sentence: I like batman because batman saved the city many times. The most frequent word is: batman The frequency is: 2 PYTHON
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade...
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User is done entering grades ELSE Count each grade as it is entered. Compute a running total of the grades entered. END IF After the user enters the sentinel of -1, calculate the average of the grades entered. When computing the average, make sure that there is...
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers....
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat, otherwise, it should terminate. Use Continue branching statement Write a program that reads an integer and display all the positive ODD numbers from 0 to n (integer entered by the user). Use CONTINUE...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT