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
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
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 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][email protected];[f2.l2.m2][email protected] BELOW IS THE EXPECTED OUTPUT IF LAST NAME IS NULL: String strOut = [f1.m1][email protected];[f2.m2][email protected]
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 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.
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...
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...
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 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 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 '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...
In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that represents an annual salary for employees. This program should all be written in the main driver program no additional classes are needed. Your program should do the following: Prompt the user for a salary continually until the user enters a sentinel value, a negative number. Keep two running totals the first is the total of all original salaries and the second is a total...