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, While Statement and some mathematical computation. Write the...
Define a problem with user input, user output, While Statement and some mathematical computation. Write the pseudocode, code and display output.
Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode,...
Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode, code and display output. Include source code and output. If no output explain the reason why and what you are going to do make sure it does not happen again aka learning from your mistakes. Problem: Pseudocode: Code: Output:
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.
USING THE IF STATEMENT & Scanner for input and println for output - Write a java...
USING THE IF STATEMENT & Scanner for input and println for output - Write a java program where the user enters a temperature as a whole number from input, and outputs a “most likely” season [either SUMMER, SPRING, FALL or WINTER] depending on the temperature entered. SUMMER would be 90 or higher SPRING   would be 70 to less than 90 FALL       would be 50 to less than 70 WINTER would be less than 50 Consider it an error if the...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT