Question

Java only Input 10 integers all adjacent duplicates.     Use a FOR loop- No error checking...

Java only

Input 10 integers all adjacent duplicates.
    Use a FOR loop- No error checking for this one - Just assume all inputs are integers
    For example if 1,3,3,4,5,5,6,6,6,2 are entered, you print 3,5,6
    (Hints: Compare previous input to next input, Print will be inside FOR loop)

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

JAVA PROGRAM :

import java.util.Scanner;

public class Sample1 {

public static void main(String[] args) {
//Scanner for reading inpout
Scanner obj = new Scanner(System.in);
int arr[] = new int[10];
for(int i=0;i<10;i++){
arr[i] = obj.nextInt();
}
int c=1;
for(int i=1;i<10;i++){
if(arr[i]==arr[i-1]){
c++;
}
else{
if(c>1){
System.out.println(arr[i-1]);
}
c = 1;
}
}
if(c>1){
System.out.println(arr[9]);
}
}
}

OUTPUT :

1 1 2 2 3 3 4 4 5 5

1

2

3

4

5

OUTPUT:

1 3 3 4 5 5 6 6 6 2

3

5

6

Add a comment
Know the answer?
Add Answer to:
Java only Input 10 integers all adjacent duplicates.     Use a FOR loop- No error checking...
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
  • Write a single program in java using only do/while loops for counters(do not use array pls)...

    Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...

  • This is in Java. Write the application, TheSentinel  to read a set of integers. Stop reading input...

    This is in Java. Write the application, TheSentinel  to read a set of integers. Stop reading input when a non-integer is read. Use this exact prompt: System.out.print("Enter an integer or Q to quit: "); Note: you will actually quit on any non-integer. Do the following things: Find and print the sum of all the even numbers Find and print the smallest of the inputs Determine if the number 7 is in the input. If 7 is in the inputs, print "7...

  • In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...

    In Java: Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen. Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen. Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final...

  • Write a JAVA method that expands a given binomial (ax + by)n, where integers a, b,...

    Write a JAVA method that expands a given binomial (ax + by)n, where integers a, b, n are user inputs. For example, if a = 2, b = -12, n = 4 are entered the method should print or return (2x - 12y)^4 = 16x^4 - 384x^3y + 3456x^2y^2 – 13824xy^3 + 20736y^4 Use the Pascal’s triangle method using only one 1-dim array to calculate all binomial coefficients. 1. Write a JAVA method that expands a given binomial (ax by)",...

  • In java please :-) 12 values have been input into array yearlyValues. Output all 12 elements,...

    In java please :-) 12 values have been input into array yearlyValues. Output all 12 elements, with 4 per line. If the elements are 10 20 30 40 50 60 70 80 90 100 110 120, the output is: 10 20 30 40 50 60 70 80 90 100 110 120 Hints: • Use a for loop with increment i += 4, rather than ++i. • Inside the for loop, just print all four elements using four print statements. An...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • JAVA Array and Loop Question. No DUPLICATES! I saw a similar question but it is not...

    JAVA Array and Loop Question. No DUPLICATES! I saw a similar question but it is not the same as this. There are two arrays, one holds time and one holds amount, each corresponding to each other. timeArray= [ 0, 2, 3, 0, 2] amountArray= [500, 100, 400, 650, 50] time = 4 sec From these I must find the maximum sum of amountArray with correspondence of timeArray being the urgency #. There is a given time limit and before that...

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

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • Answer using programming in C only. 6 pts Use a while loop to complete the following:...

    Answer using programming in C only. 6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation

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