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

  • 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...

  • (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...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • 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.

  • Small Basic Programming Question: Average score Write a program that uses loops to collect data and...

    Small Basic Programming Question: Average score Write a program that uses loops 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...

  • Write the code in java. Just a simple code with no While loop. If-else statement is...

    Write the code in java. Just a simple code with no While loop. If-else statement is permitted. Thanks. Game rule: paper beats rock; rock beats scissor and scissor beats paper. Paper-0; rock-1; sissor 2 Computer generates random number 0-2 int computerGuess; computerGuess (int) (Math.random ()*3) You are asked to enter value 0-2 Use at least one switch statement DETERMINE WHO WINS OR TIE BECAUSE BOTH PICKED SAME VALUE PRINT-what computer picked, what you picked and who won "Computer picked rock,...

  • Java use for loop (nested for loop) if/else possible on blue J. (row *col)%2 for 0's and 1's.

    Java use for loop (nested for loop) if/else possible on blue J. (row *col)%2 for 0's and 1's. Write a program to generate the below table: . The table should be able to vary in size based on a class constant called SIZE; minimum of 1, maximum of 9. . The O's and 1's can and should be generated by evaluating a mathematical expression using the row and column numbers Think about the operators: +-* / % . The output...

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
ADVERTISEMENT