Question

In: Computer Science

ASAP PLEASE!!!! USING JAVA /* 1. When should you use a do-while loop? ** Write your...

ASAP PLEASE!!!! USING JAVA

/*

1. When should you use a do-while loop?

** Write your answer as a multi-line Java comment **

*/

/*

2. Identify the algorithm that matches this code snippet. Your choices are:

  sum and average, counting matches, first match, prompt until match, and

  comparing adjacent values.  Write your answer below the coded.     

  int firstNum = 0;

  int number = scnr.nextInt();

  while (scnr.hasNextInt())

  {

  int input = scnr.nextInt();

  if (input == number)

  {

  firstNum++;

  }

  }

  My answer is:

*/

/*

3.

  Write a Java code snippet with a do-while loop to validate user input. Prompt the

  user to enter a value less than 100. If the user doesn't enter a value less than 100,

ask again until they provide a valid number. Print the valid number to the console.

*/

/*

4. Write a Java code snippet with a nested for loop to

  print five rows of six random integers between 5 and 10 inclusive.

*/

/*

5. Currency conversion: Write a snippet that first asks the user to type

  today's US dollar price for one  Euro. Then use a loop to:

-- prompt the user to enter a Euro amount. (allow decimals)

-- convert that amount to US dollars. (allow decimals)

-- print the amount to the screen, formatted to two decimal places

Use 0 as a sentinel to stop the loop.

*/

Solutions

Expert Solution

Please ask 1 question at a time. I have done first 3

1
We should use a do while loop when we need the loop to run atleast once. For examle , while validating user input, we can use it, as we need the loop to run atleast once, for user to input


2)The algorithm is counting matches
We first take an integer input. Then we take more integer inputs, and increase counter if any input matches the first integer.

3)

int num;

do{

System.out.println("Enter a value less than 100: ");

num = sc.nextInt();

}while(num>=100);

System.out.println("You entered: " + num);


Related Solutions

Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
every code should be in java Program 1: Write a while loop that sums the integers...
every code should be in java Program 1: Write a while loop that sums the integers from 1 to 10, excluding 3 and 6. Print the sum. [Hint: Use logical operators] Program 2: Write a for loop that attempts to display the numbers from 1 to 10, but terminates when the control variable reaches the value 6. Program 3: Write a do...while loop that prints the integers from 10 to 0, inclusive.
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
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...
Q1:Write a Java program to find Fibonacci Series using 1) using for loop 2) using while...
Q1:Write a Java program to find Fibonacci Series using 1) using for loop 2) using while loop To Understand what the Fibonacci series is: The Fibonacci sequence is a series of numbers where a number is the sum of the previous two numbers. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. Q2: Write a Java program to find the Factorial of a number using a while loop. To...
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT