+ 3
Where should we use case sensitive in Java
I am noob help me
5 ответов
+ 10
for creating veriables or method
+ 2
The class:
public class Program{
}
inside in it the so main method which you need to execute your code:
public static void main(String[] args){
}
methods which you call:
* .nextLine() -> Scanner method
* .parseInt() -> Integer method
* .substring() -> String method
* out.println() -> System method
variables:
* scanner from type Scanner
* value from type String
* numberOne from type int
* numberTwo from type int
Scanner and String are objects (instance of a class).
int is a primitive data type.
Class names or objects starts with capital letter. To create an object you need the keyword new:
Scanner scan = new Scanner(System.in);
String is a bit different because it is an object but you can use it like a primitive data type.
variable names and methods starts with lower case letters and each next word with capital letters: numberOne instead of numberone
And methods have always brackets at the end of the name:
Integer.parseInt()
or value.substring()
myMethod()
myVariable
+ 1
Maheedhar Vegesana Because String is a class in java and in java first letter of class name must be capital.
String str = new String("hello world");
Also we can write:
String str = "hello world";
And I think it is for java.lang.String
If it is wrong plz correct it!
0
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String value = scanner.nextLine();
int numberOne = (Integer.parseInt(value.substring(0, 1)) + (Integer.parseInt(value.substring(1, 2))));
int numberTwo = (Integer.parseInt(value.substring(2, 3)) + (Integer.parseInt(value.substring(3, 4))));
System.out.println("Result: " + numberOne + numberTwo);
}
}
what are variables and methods in this code
0
and why String starts with ^S