Question
can i get an example of a simple code using the following picture in java
20% Basic Java usage of comments next to the program variables declaration: input/output data types
0 0
Add a comment Improve this question Transcribed image text
Answer #1
package abc;
import java.util.*;//import statements for importing the packages
class MySite//main class as it contains main method
{//start of main class
        public static void main(String args[])//main method
        {//start of main method
                Scanner sc=new Scanner(System.in);//scanner class used to give user input at the run time
                int a,b,sum;//declaration of integer type variables
                float c,d,diff;//declaration of float type variables
                System.out.println("enter values of a and b");//prints whatever written in double quote to the output screen
                a=sc.nextInt();//method to assign user input integer value to "a" at run time
                b=sc.nextInt();//method to assign user input integer value to "b" at run time
                sum=a+b;//adds the value of a and b and stores the value in sum
                System.out.println(sum);//prints the values of sum to the output screen
                System.out.println("enter values of c and d");
                c=sc.nextFloat();//method to assign user input floating type value to c at run time
                d=sc.nextFloat();//method to assign user input floating type value to d at run time
                diff=c-d;//calculate the difference between c and d and stores it in the diff.
                System.out.println(diff);//prints the value of "diff" to output;
        }//end of the main method
}//end of main class

JAVA COMMENTS:

In java comments are used to explain the codes and to make it more understandable to the person who executes/reads the code.

comments are of two types in java :

single line comments
multi line comments


SINGLE LINE COMMENTS:

Single-line comments start with two forward slashes (//).

The text between // and the end of the line will not be executed by Java

MULTI LINE COMMENTS:

always multi line comments start with /* and ends with */.

text between /* and */ will not be executed by Java program.

JAVA VARIABLES:

In java variables are used for the storing of the data.

The variable may of any type like

Intergers
floating points
strings
JAVA DATA TYPES:

Data types are of two types in java

Primitive data types
Non-Primitive data types


PRIMITIVE DATA TYPES:

A data type which specifies the size and type of variable values and it has no additional method.

there are 8 primitive data types

byte
short
int
long
float
double
boolean
char


NON-PRIMITIVE DATA TYPES:

Non-primitive types are created by the programmer and is not defined by Java (except for String).Non-primitive data types refer to the objects so they are called reference types in java .These types can be used to perform certain operations and to call some methods.

some of non primitive data types are

Strings
Arrays
Classes
Interface

Add a comment
Know the answer?
Add Answer to:
can i get an example of a simple code using the following picture in java 20%...
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
  • can i get an example of a java code using a class and bulit in methods...

    can i get an example of a java code using a class and bulit in methods inculding everything else in the picture 20% Control structures decision: if. else if.... Else switch ... case (optional) repetition (at least 2 iterations) while, do...while for 20% Classes (at least 2 classes) 10% Methods (at least 2 methods) user-defined and/or built-in methods 10% Arrays (at least 1 set of array) 20% User Interface Menu like starting point User friendliness Error free

  • can i get an example of a java code using a class and user defined menthod...

    can i get an example of a java code using a class and user defined menthod with everything else listed in the picture 20% Control structures decision: if. else if.... Else switch ... case (optional) repetition (at least 2 iterations) while, do...while for 20% Classes (at least 2 classes) 10% Methods (at least 2 methods) user-defined and/or built-in methods 10% Arrays (at least 1 set of array) 20% User Interface Menu like starting point User friendliness Error free

  • PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS...

    PLEASE UPLOAD or Write a simple PSEUDO CODE AND JAVA CODE for this program WITH COMMENTS IN BOTH TELLING WHAT EACH PART DOES. (I NEED BOTH CODES NOT JUST ONE OR THE OTHER) Problem Statement A golf club has a small tournament consisting of five golfers every weekend. The club president has asked you to design a program that does the following: Reads player’s names and their scores from the keyboard for each of the five golfers and simulates writing...

  • I need help with the following. I need to write a program code in Java using...

    I need help with the following. I need to write a program code in Java using NetBeans. It is from How to Program Java book Chapter 2. This program should calculate the packing of Candles. First read: The number of candles The number of candles that fit in each case Then calculate and print: The number of full cases The number of candles left over (partial case) If this order is large (more than 5 full cases needed) An extra...

  • JAVA Programming - Create a very simple single-class program (the most basic code form possible), which...

    JAVA Programming - Create a very simple single-class program (the most basic code form possible), which demonstrates the various concepts, methods, with comments explaining each part, following the topics: //Understanding String Data Problems // Comparing String Values //Empty and Null Strings //Using a Variety of String Methods //Converting String Objects to Numbers //StringBuilder and StringBuffer Classes

  • in BASIC/BEGINNER OBJECT ORIENTATED JAVA Please write code for the following program using comments explaining the...

    in BASIC/BEGINNER OBJECT ORIENTATED JAVA Please write code for the following program using comments explaining the code. (You can hand write this). Give a UML example illustrating AGGREGATION. Include classes, fields, methods, instance fields. USE ONE SUPER CLASS AND TWO SUB CLASSES. Include pcode for at least one method of each class. Explain the whole part relationship and if this a deep or shallow copy.

  • Java I: Create a Java program that will accept the price of an item and the...

    Java I: Create a Java program that will accept the price of an item and the quantity being purchased of that item. After accepting the input, calculate the amount of the purchase (based on the price and quantity), calculate the sales tax on the purchase, then output the product price, quantity, subtotal, sales tax, and the total sale based on the output format shown below. Structure your file name and class name on the following pattern: The first three letters...

  • What this Assignment Is About: Review on Java I topics, such as primitive data types, basic...

    What this Assignment Is About: Review on Java I topics, such as primitive data types, basic I/O, conditional and logical expressions, etc. Review on Java loops. Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are...

  • Overview These exercises will allow you to have some practice with basic Java file Input/Output. In...

    Overview These exercises will allow you to have some practice with basic Java file Input/Output. In addition, you will also have an opportunity to have more practice with methods and arrays.   Objectives Practice with programming fundamentals Variables - Declaration and Assignment Primitive types Arithmetic Expressions Simple keyboard input and text display output Branching - if-elseif-else syntax Loops - simple while loops, nested while loops Methods - functions and procedures ArrayLists - collections of variables File I/O Works towards the following...

  • (JAVA) Thumbs up for full answer! using NetBeans Using the Scanner class, get a user's name...

    (JAVA) Thumbs up for full answer! using NetBeans Using the Scanner class, get a user's name and two integers. Once you have that input, process it, and output the following: The input here is only representative. The program should accept any name or integer and perform the appropriate calculations. Do attempt some simple formatting.

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