Question

WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP) BELOW ARE INSTRUCTIONS: IF USER ENTERS:...

WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP)

BELOW ARE INSTRUCTIONS:

IF USER ENTERS:

"1, 2, 3"

THIS IS THE Expected Output:

1,1,2,2,3,3

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

Here the solution for above problem in java. I have used print method in java to print output in same line, also for to avoid comma in last element i ran the loop till second last element

CODE IN JAVA


import java.util.*;
import java.io.*;
public class Main
{
   public static void main(String[] args) {
//SCANNING FOR INPUT  
       Scanner sc = new Scanner(System.in);
String line = sc.next();
//SPLITING THE STRING BASED ON COMMAN
String[] vector = line.split(",");
int x;
int i;
//ITERATING THROUGH ALL NUMBER PRESENT
for(i=0;i<vector.length-1;++i)
{
//PARSING THE INTEGER X
x=Integer.parseInt(vector[i]);
//PRINTING THE VALUE ON CONSOLE PRINT METHOD IS USED AS IT DOES NOT LEAVE NEW LINE
System.out.print(x);
System.out.print(",");
System.out.print(x);
System.out.print(",");
}
//FOR LAST ELEMENT IGNORING THE LAST COMMA
x=Integer.parseInt(vector[i]);
System.out.print(x);
System.out.print(",");
System.out.print(x);
System.out.println("");
  
   }
}
OUTPUT OF CODE

SCREENSHOT OF CODE

Add a comment
Know the answer?
Add Answer to:
WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP) BELOW ARE INSTRUCTIONS: IF USER ENTERS:...
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 JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN...

    WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN THE CODE: Map m1 = new HashMap(); m1.put("firstName","f1"); m1.put("lastName","l1"); m1.put("middleName","m1"); Map m2 = new HashMap(); m2.put("firstName","f2"); m2.put("lastName","l2"); m2.put("middleName","m2"); BELOW IS THE EXPECTED OUTPUT IF GETTING ALL THE VALUES FROM THE INPUT: String strOut = [f1.l1.m1]f1.l1.m1@abc.com;[f2.l2.m2]f2.l2.m2@abc.com BELOW IS THE EXPECTED OUTPUT IF LAST NAME IS NULL: String strOut = [f1.m1]f1.m1@abc.com;[f2.m2]f2.m2@abc.com

  • Write a program in JAVA that asks the user to enter an integer. Store the integers...

    Write a program in JAVA that asks the user to enter an integer. Store the integers in an array. Allow for up to 10 integers. When the user enters -1, the program should end. Print the number of integers entered as well as the number of times each integer was entered.

  • Write a program that accepts numbers entered by the user until the user enters a zero....

    Write a program that accepts numbers entered by the user until the user enters a zero. The program then must display the largest value that is smaller than zero. This should be java program

  • Write a Java program that reads in a word from the user and outputs each character...

    Write a Java program that reads in a word from the user and outputs each character of the word on a separate line. For example, if the user enters the input "Joe", your program should output: J o e You need to use a for-loop.

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • In Java Write a program that will ask the user for integers and print if the...

    In Java Write a program that will ask the user for integers and print if the integer is positive, negative or zero. The program should continue asking for integer until the user enters a negative value.

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

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