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.
Program using java Take user input and give corresponding output. A user is considering different options...
Program using java Take user input and give corresponding output. A user is considering different options of operating air conditioning. Depending on room temperature (here, room temperature is given by user), this program should give different instructions. There are three scenarios. - If temperature is above 90, the program should output “cooling”. -If the temperature is below 70, the program should output “heating”. -Otherwise, the program should output “stopped”. For example, if user enters “95”, this is how the program...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
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.
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two...
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two names one for their Pokémon, and one for the computers Pokémon Make two integer variables to hold the HP of each Pokémon, HP should be 20 for both Pokémon’s. Use Math.random() to determine the amount of damage caused, and which move the computer will select. The range of damage that can be done is up to you. Output to the user an attack menu...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT