OUTPUT:
[Link]("Hello World"); ------> The next output after this will be on the same line as this;
[Link]("Hello world); ------> The next output after this will be on a new line;
INPUT:
Firstly you need to import the scanner at the top line before the class
import [Link]; ---> This imports the scanner
Scanner bucky = new Scanner ([Link]); ---> This assigns the value given by user to a
variable called as bucky.
Then to take input and to store in any variable
boy = [Link](); ---> This assigns the value user inputs to a variable 'boy'
nextInt is used because boy is 'int'
use nextLine for string and so on.
after taking input from the keyboard, inorder to print it out:
[Link]([Link]); ---> The nextLine is used so the program waits for the
input to be given and doesnt directly jump to output
SIMPLE ADDITION CALCULATOR:
import [Link];
public class apples {
public static void main (String args[]) {
Scanner bucky = new Scanner ([Link]);
double fnum, snum, answer;
[Link]("Enter a number");
fnum = [Link]();
[Link]("Enter a number to add");
snum = [Link]();
answer=fnum+snum;
[Link]("The answer is " + answer);
IF ELSE SYNTAX
int test = 6;
if (test <= 9)
[Link]("Yes");
else
[Link]("This is else");
int test = 6;
if (test <= 9)
[Link]("Yes");
}
else
[Link]("This is else");
NOTE: "&&" this means that conditions on both sides must be met
inorder to print the true (if) statement.
"||" this is used as "or". ie either one condition is true the
value is true.
Example of if else syntax:
import [Link];
public class apples {
public static void main (String args[]) {
int boy, girl;
Scanner rohan = new Scanner ([Link]);
[Link]("Enter the Age of the Boy");
boy= [Link]();
[Link]("Enter the age of the girl");
girl = [Link]();
if(boy>=18 || girl<=50)
[Link]("Welcome to Tinder");
else
[Link]("FUCK OFF");
SWITCH CASE:
simple Calculator with 0 errors
import [Link];
public class apples {
public static void main (String args[]) {
[Link]("Which operation do you want to
perform");
[Link]("1. Add 2. Subtract 3. Multiply 4.
Divide");
Scanner scan = new Scanner ([Link]);
char op;
double fnum,snum,ans;
op = [Link]().charAt(0);
[Link]("Please enter first number");
fnum = [Link]();
[Link]("Please enter second number");
snum = [Link]();
switch(op)
case '1':
ans = fnum+snum;
[Link]("The addition is "+ ans);break;
case '2':
ans = fnum - snum;
[Link]("The subtraction is " + ans);break;
case '3':
ans = fnum * snum;
[Link]("The multiplication is " + ans);break;
case '4':
ans = fnum/snum;
[Link]("The division is " + ans);break;
default :
[Link]("Madarchod jitna bola hai utne me
se select kar. Bakchodi mat kar");break;
}
}
WHILE SYNTAX:
int counter =0;
while (counter <10)
[Link](counter);
counter++;
MULTIPLE CLASSES:
There is a class called as tuna. (Our main class is apples)
in tuna class we write a code:
public class tuna {
public void simplemessage(String name)
[Link]("Hello "+name);
}
There is no main funtion/ method in class tuna, we go to our main
class apples and use this class tuna as:
public class apples {
public static void main (String args[]) {
Scanner scan= new Scanner([Link]);
Sysout(“Enter Your name here: ”);
String name = [Link]();
tuna tunaObj = new tuna();
[Link](name);
The tunaObject, it is an object. In tuna class there can be many
functions, to know which function we want to call, we use an object.
We create a new object as shown then we use the object.