TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Tutorials

Sample Java Programs to Practice

Overview

We will practice basic programming in Java. We will discuss basic operations on data types like int and String. We will run the program and look at the desired output.

Problem Statement

Declare 2 datatype variables and follow the steps below to write your program in Java.

Steps:
1.Declare 2 variables: one int, one String variable for example  20 , John ( or the name of your best friend.)
2.Add value 10 to the above integer and print.
3.Concatenate Hi to your best friend’s name and print.

Sample:
20
John

 

Desired Output

Sample output of your program should be :
30
Hi John

Try to practice the code in your fav IDE like Eclipse or IntelliJ.

 

Sample Code Snippet

public class Day2 {

 public static void main(String[] args) {
 // TODO Auto-generated method stub
 
 int i = 20 ;
 String s = "John" ;
 
 
 System.out.println(i + 10);
 System.out.println("Hi " + s);
 
 System.out.println("Another way :");
 
 System.out.println(i + 10 );
 System.out.println("Hi ".concat(s));
 }

}

 

Output :

30
Hi John
Another way :
30
Hi John

The System class contains several useful class fields and methods. It cannot be instantiated, since its constructor System() is not visible and not public.

The following facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.

Conclusion

Explore the class System methods and their usage. Also, a handy way to explore things is to look at the Java API.

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Related Posts

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java Tutorials /

Exceptions in Java Programs

‹ Java Access Modifiers› Read from Standard Input using Scanner

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version