Question: PLEASE HELP!! When answering please follow the format provided : ) 4 . 5 . 1 : Read two positive inputs, the first less than
PLEASE HELP!!
When answering please follow the format provided :
: Read two positive inputs, the first less than the second.
Complete this program, prompting the user to enter two positive numbers a and b so that a is less than b
import java.util.Scanner;
public class TwoNumbers
public static void main
String
args
Scanner in
new Scanner
System
in
;
int a;
int b;
HINT: Choose an appropriate loop and a loop condition
Your code goes here
System.out.println
"Enter two positive integers, the first smaller than the second."
;
a
in
nextInt
;
System.out.println
First:
a
;
b
in
nextInt
;
System.out.println
Second:
b
;
Your code goes here
This line should only be printed when the input is correct
System.out.println
You entered
a
and
b
;
: Read numbers until zero or duplicate.
Write a do loop that reads integers and computes their sum. Stop when a zero is read or the when the same value is read twice in a row. For example, if the input is
then the sum is
and the loop stops.
import java.util.Scanner;
public class DoSum
public static void main
String
args
Scanner in
new Scanner
System
in
;
int previous;
int sum
;
int x
;
do
Your code goes here
while
Your code goes here
;
System.out.println
Sum:
sum
;
: Reading data with a sentinel
Complete this program that reads integers and computes their sum. Use
as a sentinel value.
import java.util.Scanner;
public class SumOfInputs
public static void main
String
args
Scanner in
new Scanner
System
in
;
int sum
;
int input;
System.out.print
Enter values,
to quit:
;
Your code goes here
System.out.println
Sum:
sum
;
: Remove duplicate words.
It is a common error to accidentally repeat a word. Write a program that reads a sentence, a word at a time, and removes any adjacent duplicates. The sentence ends when you read a word that ends in a period. The sentence will have at least two words.
import java.util.Scanner;
public class RemoveDuplicateWords
public static void main
String
args
Scanner in
new Scanner
System
in
;
String word
in
next
;
boolean done
Your code goes here
while
done
String previous
Your code goes here
word
Your code goes here
if
word
endsWith
word
Your code goes here
done
Your code goes here
if
Your code goes here
System.out.print
previous
;
System.out.print
word
;
Thank you soo much!!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
