Question

Question: Write a java class to accept data from user via keyboard for (1) User name (2) three integer values,then calculate
0 0
Add a comment Improve this question Transcribed image text
Answer #1

gogetter solutions

code:-

import java.util.*;
public class Main {
  
   public static void main(String[] args) {
       String userName = "";
       int number1, number2, number3;  
       int sum;
       double average;
      
       Scanner sc = new Scanner(System.in);
       userName = sc.nextLine();
       number1 = sc.nextInt();
       number2 = sc.nextInt();
       number3 = sc.nextInt();
         
       sum = number1 + number2 + number3;
       average = sum / 3;
         
       System.out.print("User Name : ");
       printValue(userName);
       System.out.print("Sum : ");
       printValue(sum);
       System.out.print("Average : ");
       printValue(average);
      
      
   }
  
   public static void printValue(Object ob) {
       System.out.println(ob.toString());
   }
}

Add a comment
Know the answer?
Add Answer to:
Question: Write a java class to accept data from user via keyboard for (1) User name...
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 Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • This program will take advantage of methods written in the Help.java class First, you will write...

    This program will take advantage of methods written in the Help.java class First, you will write a new method in Help.java. This method will be named: addArray) and will accept an array of integers as input. This method will calculate the sum of all values in the array and return the resulting sum. Remember that the array being passed to the method may be of ANY length. (Use the existing methods in the Help.java class to help you remember how...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • Write a Java class that examines a single character input from the keyboard. Follow this dialog...

    Write a Java class that examines a single character input from the keyboard. Follow this dialog to guide your coding: Type a single character and press Enter: m Digit: No Letter: Yes Lowercase: Yes Toggle case: M Note: There is no "next" method of the Scanner class to obtain input from the keyboard of data type char. It simply doesn't exist so you need a workaround. Store the end-user input into a String variable; then extract the first character using...

  • ANS (2) 0R hat output is produced by the following code if user enters these values...

    ANS (2) 0R hat output is produced by the following code if user enters these values for a question asked by the progran .User entered 3 Enter a positive integer value! (enter -1 to end) :3 Enter a positive integer value! (enter -1 to end) five Enter a positive integer value! (enter -1 to end) :7 Enter a positive integer value! (enter -1 to end) :-1 User entered five -User entered 7 ...User entered -1 import java.util.Scanner: class Verify input...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...

    Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods:   getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.   getAverage. This method should accept a two-dimensional array...

  • In Java, write a program that asks the user for the name of a file. The...

    In Java, write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage

  • [JAVA] Write a class "customer" that has data fields "name" and "lastName." In addition, the accessor...

    [JAVA] Write a class "customer" that has data fields "name" and "lastName." In addition, the accessor methods "get name" and "get last name" should print out the customer name. The class should contain a nested class CreditCard that has a single method "pay." The CreditCard method "pay" should print "Paid." The customer class constructor should take in parameters "name" and "last name." The customer class should have a method "pay" that calls the nested class pay method. Create a test...

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