Object-oriented programming - Laboratory 1
Schedule
Next
Temat: IntelliJ - basics introduction to java
IntelliJ
We will use IntelliJ on create Java program.
First Java program
Hello World
a+b
a+b with classes
Final code from classes
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Give me two numbers in separate lines:");
number a = new number();
a.setValue(Integer.parseInt(in.nextLine()));
number b = new number();
b.setValue(Integer.parseInt(in.nextLine()));
number c = new number();
c.setValue(a.getValue() + b.getValue());
//int a = Integer.parseInt(in.nextLine());
//int b = Integer.parseInt(in.nextLine());
//int c = a+b;
System.out.println(c.getValue());
//System.out.println("Give me some String:");
//String something = in.nextLine();
//System.out.println(something);
}
}
public class number
{
private int value;
public int getValue()
{
return value;
}
public void setValue(int x)
{
value = x;
}
}