Statements (1).pdf - Java statements Java statements go...

  • No School
  • AA 1
  • 1

This preview shows page 1 out of 1 page.

Java statements Java statements go between the { and } after public static void main(String[] args) , and the main method goes between the { and the } after public class Whatever . Every Java statement ends with a semicolon. To start, there are just three kinds of Java statements. 1. Declarations create new variables in Java. To declare a variable, put the data type of the variable ( byte , short , i n t, long , float , double , boolean , char , String , Scanner , etc.), then at least one space, then the variable name, and end with a semicolon. Examples: int count; double percent; char letter; String answer; 2. Assignments change the values of the variables. To assign a value to a variable, put the variable name, then an = sign, then the value that you want it to have, and end with a semicolon. Examples:
Image of page 1

Unformatted text preview: count = 5; percent = 75.0; letter = 'A'; answer = "yes"; 3. Output statements start with either System.out.print , to stay on the same line, or System.out.println to go to the next line. In parentheses () after that, put either a variable name to show the value of the variable on the screen, or some words in " quotes " to show those words on the screen. Output statements also end with a semicolon. Examples: // Show the value of count and go to the next line. System.out.println(count); // Display "The answer is ", including the space // after "is" and stay on the same line. System.out.print("The answer is "); // Show the value of answer and stay on the same line. System.out.print(answer); // Just go to the next line. System.out.println();...
View Full Document

  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask bonus questions You can ask questions ( expire soon) You can ask questions (will expire )
Answers in as fast as 15 minutes