Question

USE JAVA. Just a basic code. We these in Blue J

2) Write a while loop that lets the user enter a number. The number should be multiplied by 10 and the result stored in the variable product. The loop should iterate as long as product contains a value less than 100. 3) Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user should be asked if he or she wishes to perform the operation again. If so, the loop should repeat. Otherwise, it should terminate.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Quesiton 2:

Here is code:

import java.util.Scanner;

public class Loop {

public static void main(String[] args) {

Scanner cin = new Scanner(System.in);

System.out.print("Enter number : ");

int product = cin.nextInt();

while (product < 100) {

product = product * 10;

}

System.out.println("Product value is : " + product);

}

}

Output:

Blue: BlueTest Project Edit Tools View Help New Class... Loop BlueJ: Terminal Window-BlueTest Compile Options Enter number: 5 Product value is: 500 Can only enter input while your programming is

Quesiton 3:

Here is code:

import java.util.Scanner;

public class Sum {

public static void main(String[] args) {

Scanner cin = new Scanner(System.in);

int choice;

do {

System.out.print("Enter number #1 : ");

int num1 = cin.nextInt();

System.out.print("Enter number #2 : ");

int num2 = cin.nextInt();

System.out.println("The sum of numbers are : " + (num1 + num2));

System.out.print("Do you like to continue (1/0) : ");

choice = cin.nextInt();

} while (choice == 1);

}

}

Output:

Add a comment
Know the answer?
Add Answer to:
USE JAVA. Just a basic code. We these in Blue J 2) Write a while loop...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a Do-While loop that asks the user to enter two numbers. The numbers should be...

    Design a Do-While 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. using visual basic

  • write a while loop that ask the user to enter two numbers. the number should be...

    write a while loop that ask the user to enter two numbers. the number should be added and the sum displayed. the loop should ask the user if he or she wish to perform the operation again. if so the loop should repeat, otherwise it should terminate. write a phyton code for this one:

  • Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks...

    Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use...

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

  • Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and...

    Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and calculate the average score over a number of tests for a number of students. The program should: 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the scores...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • PSEUDOCODE WORKBENCH PROBLEMS Very Difficult and was wondering if I could get a step by step...

    PSEUDOCODE WORKBENCH PROBLEMS Very Difficult and was wondering if I could get a step by step solution? in a programming logic and design we are writing pseudo code in an algorithm workbench: the question reads as follows : Design a While loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in a variable named product. The loop should iterate as long as product contains a value less than 100. the...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • In Java, write a program using a loop that asks the user to enter a series...

    In Java, write a program using a loop that asks the user to enter a series of decimal numbers. The user must enter -88 to end the input of the decimal numbers. After the user enters all numbers, the program should display the sum of all numbers entered.

  • Write a while loop in java that will let the user enter a series of integer...

    Write a while loop in java that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT