1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alborosie
3 years ago
5

Write a Java program to accept an item's name and price from the user and output them to the console

Computers and Technology
1 answer:
Anit [1.1K]3 years ago
6 0

Answer:

// program in java.

// package

import java.util.*;

// class definition

class Main

{// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // scanner object to read inputs

Scanner scr=new Scanner(System.in);

 // variables

String name;

   double price;

   System.out.print("Enter item's name: ");

   // read item's name

   name = scr.next();

   System.out.print("Enter item's price: ");

   // read item's price

   price= scr.nextDouble();

   // print name

   System.out.println("name of item is:"+name);

   // print price

   System.out.println("price of item is:"+price);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read name & price of item from user and assign it to variables "name" & "price" respectively with scanner object.Then print the name and price of item .

Output:

Enter item's name: Apple                                                                                                  

Enter item's price: 100                                                                                                    

name of item is:Apple                                                                                                      

price of item is:100.0

You might be interested in
What is the alogarithm for solving the perimeter of a triangle
Lapatulllka [165]

Answer:

 P = a + b +c

Explanation:

jkaksbajksnsn

3 0
3 years ago
Design and implement an algorithm that gets a list of k integar values N1, N2,...Nk as well as a special value SUM. Your algorit
Fittoniya [83]

Answer:

The algorithm is as follows:

1. Start

2. Input List

3. Input Sum

4. For i = 0 to length of list - 1

4.1 num1 = List[i]

5. For j = i to length of list - 1

5.1 num2 = List[j]

6. If SUM = num1 + num2

6.1 Print(num1, num2)

6.2 Break

The algorithm is implemented in python as follows:

def checklist(mylist,SUM):

     for i in range(0, len(mylist)):

           num1 = mylist[i]

                 for j in range(i+1, len(mylist)):

                       num2 = mylist[j]

                       if num1 + num2== SUM:

                             print(num1,num2)

                                   break;

Explanation:

I'll explain the Python code

def checklist(mylist,SUM):

This line iterates from 0 to the length of the the last element of the list

     for i in range(0, len(mylist)):

This line initializes num1 to current element of the list

           num1 = mylist[i]

This line iterates from current element of the list to the last element of the list

                 for j in range(i+1, len(mylist)):

This line initializes num1 to next element of the list

                       num2 = mylist[j]

This line checks for pairs equivalent to SUM

                       if num1 + num2== SUM:

The pair is printed here

                             print(num1,num2)

                                   break;

6 0
3 years ago
The most common type of local correction system is
STALIN [3.7K]
The answer is A county-based correctional system.  The most common type of local correction system is a county-based correctional system.  
6 0
4 years ago
Which two sentences uses the colon correctly?
faust18 [17]
You much list something after a colon.
For example
Kaylina's bag included:
Food,Books,Makeup,and a brush.
5 0
3 years ago
Which of the following statements are true of software engineers? Check all of the boxes that apply. They are responsible for wr
Zina [86]

Answer:

First two statements: yes. Last two: not so much.

But many of the better ones do have advanced degrees, but some don't.

The laboratory statement is silly; they sit behind a set of screens figuring out stuff and writing code.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Explaim Why the shape of a cell is hexagonal
    15·1 answer
  • Discuss Hashing and how it is utilized within the IT industry. Also, discuss how Hashing can improve our sorting and searching r
    12·1 answer
  • The most effective way to perform data entry is to keep your hands on the keyboard and press to move to the text cell in the row
    10·1 answer
  • How do you change brightness on acer laptop?
    7·1 answer
  • Explain the function of the Ribbon in Microsoft Word.
    15·1 answer
  • At the aquarium Grandma Simpson hugged the dolphin is that passive or active sentence​?
    6·1 answer
  • Web résumés are posted to the Internet in HTML format.<br> true or false
    9·2 answers
  • Along a road lies a odd number of stones placed at intervals of 10 metres. These stones have to be assembled around the middle s
    12·1 answer
  • Someone please make a random question with an easy answer because i need one more brainliest to UPGRADE!
    7·2 answers
  • Math and science are the foundation from which drafters work<br><br> True<br> False
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!