Java - Util.scanner Apples (Main (String ) (Scanner Scanner (System.)
Java - Util.scanner Apples (Main (String ) (Scanner Scanner (System.)
System.out.print("Hello World"); ------> The next output after this will be on the same line as this;
System.out.println("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
Scanner bucky = new Scanner (System.in); ---> This assigns the value given by user to a
variable called as bucky.
System.out.println(bucky.nextLine); ---> The nextLine is used so the program waits for the
input to be given and doesnt directly jump to output
import java.util.Scanner;
fnum = bucky.nextDouble();
snum = bucky.nextDouble();
answer=fnum+snum;
IF ELSE SYNTAX
int test = 6;
if (test <= 9)
System.out.println("Yes");
else
System.out.println("This is else");
int test = 6;
if (test <= 9)
System.out.println("Yes");
}
else
System.out.println("This is else");
NOTE: "&&" this means that conditions on both sides must be met
inorder to print the true (if) statement.
import java.util.Scanner;
boy= rohan.nextInt();
girl = rohan.nextInt();
if(boy>=18 || girl<=50)
System.out.println("Welcome to Tinder");
else
System.out.println("FUCK OFF");
SWITCH CASE:
import java.util.Scanner;
char op;
double fnum,snum,ans;
op = scan.next().charAt(0);
fnum = scan.nextDouble();
snum = scan.nextDouble();
switch(op)
case '1':
ans = fnum+snum;
case '2':
case '3':
case '4':
ans = fnum/snum;
default :
}
}
WHILE SYNTAX:
System.out.println(counter);
counter++;
MULTIPLE CLASSES:
System.out.println("Hello "+name);
}
tuna.simplemessage(name);