[U]Integer Types (from smallest to largest)[/U]
byte
short
int
long
[U]Floating Point Types[/U]
float
double
[U]String Types
[/U]char
String
And then also there is the boolean, not sure what type it is though.
public static void main(String[] args)
{
//code in here
By the way, two slashes like this // is a comment and will not be read as code by your program. You can also do a multi - line comment by doing this
/*
* Comment in here
* etc
*/
}
System.out.println(""); //prints out whatever string is inside the "". The println means it will print on that line. Which means it will go to a new line each time
System.out.print(""); //Just using print means it prints out and does not go to a new line
\n - new line
\t - tab
\b - backspace/r - return
\' - Inserts a single quote
\" - Inserts a double quote
\\ - Inserts a backslash
public class FunWithString
{
public static void main(String [] args)
{
System.out.println("This is a String"); //String is an object data type
System.out.print("Roses are Red, ");
System.out.println("Violets are Blue, ");
System.out.println("\tbut I have a \"committment\" issues");
System.out.println("so I think we should be friends, \nat this point in our relationship\\journey.");
System.out.println("This is concatenation " + 24 + 45);
System.out.println("This is adding " + (24+45));
int num1 = 10;
System.out.println("The total is: " + num1 + " boxes.");
String s1 = "The total is: ";
String s2 = "Banana";
String s3 = "Apple";
String s4 = "Orange";
String s6 = "Apple";
System.out.println(s2 + s3);
System.out.println(s3.concat(s4));
System.out.println(s4.length());
System.out.println(s4.substring(1,4));
String s5 = s4.substring(1, 2);
System.out.println(s5);
char c1 = s4.charAt(1);
System.out.println(c1);
System.out.println(!(s4.equals(s6)));
s4 = s4.toUpperCase();
s3 = s3.toLowerCase();
}
}
public class Class1
{//Start class
public static void main (String[] args)
{//Start main
System.out.print("Hellow World!");
System.out.println("Yay!");
//Integer Data Type - Primitive Data type
// 4 integer data types - byte, short, int, long ///////////////////////////////
byte b1; //assigned
b1 = 0; //initialized //256
short s1 = 0; //assigned and initialized
int num1 = 0;
long dig1 = 0;
int num2 = 0, num3 = 4, num4 = 7;
byte b2, b3 = 10, b4 = 1;
int dayOfWeek = 1; //good variable name
int totalPay = 0;
int NUMBER_OF_WIDGETS = 0;
//Floating Point Variables - Primitive Data Types //////////////////// float, double
float f1 = 0.0F;
double d1 = 0.0D;
int iResult = 0;
double dResult = 0.0;
iResult = 4/3;
dResult = 4/3; //assignment conversion
System.out.println(iResult);
System.out.println(dResult);
dResult = 4.0/3; //Arithmetic Promotion
float fResult = (float)4.0/(float)3.0;
iResult = (int)(4.0/3.0); //casting
System.out.println(dResult);
System.out.println(4.0/3.0);
System.out.println(4.0F/3.0F);
num2 = 4;
num2++; //num 2 = num2 + 1;
System.out.println(num2);
System.out.println(++num2);
System.out.println(num2--);
System.out.println(num2);
System.out.println(--num2);
/*Operations on integers: +, -, *, /, %, ++, --, +=, -= , *=, /= */
num2 = 5;
num2*=3; //num2 = num2 * 3;
System.out.println(num2);
num2-=7; //num2 = num2 - 7;
System.out.println(num2);
num2 %= 3;
System.out.println(num2);
float f2 = 0.0F;
f2 = 1.0F;
System.out.println(f2);
//Primitive Data Type: boolean
boolean flag = true;
boolean bool1 = false, boo2;
/*boolean operators: == "equal to"
* != "not equal"
* && "and"
* ! "not"
* || "or"
* > "greater than"
* < "less than"
* <= "less than or equal to"
* >= "greater than or equal to"
*/
//Primitive Data type: character
char c1 = 'a';
char c2 = 'A',c3,c4='#';
//Operations with characters: <, >, <=, >=, =, !=
System.out.println('a'=='A';
}//End main
}//End class
//End file
import java.util.Scanner;//imports the scanner class
import java.text.DecimalFormat;//imports the decimal formatter
public class UserInput
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);//Declares the Scanner in scan
System.out.println("Enter a number: ");
int num = scan.nextInt();//so scan.nextInt takes in an integer and stores it in num
scan.nextLine();//takes in a string
System.out.println("What is your name?");
String name = scan.nextLine();//takes in the string and stores it in name
System.out.println("Enter a decimal:");
double dec = scan.nextDouble();//takes in the decimal and stores it in dec
System.out.println("num = " + num + ", name = " + name + ", and dec = " + dec);//prints out all the things that were entered by the user
DecimalFormat decFormat = new DecimalFormat("0.00");//2.00, it will always put .00
//("0.##") will put 0.number
//("0000") = 0001 when 1 is entered
/*f2 = (float)4/5 = 0.8
f2 = (float)(4/5) = 0.0
import java.text.NumberFormat;
NumberFormat percent = NumberFormat.getPercentInstance();
*/
}
}
[U]Integer Types (from smallest to largest)[/U]
byte
short
int
long
[U]Floating Point Types[/U]
float
double
[U]String Types
[/U]char
String
And then also there is the boolean, not sure what type it is though.
public static void main(String[] args)
{
//code in here
By the way, two slashes like this // is a comment and will not be read as code by your program. You can also do a multi - line comment by doing this
/*
* Comment in here
* etc
*/
}
System.out.println(""); //prints out whatever string is inside the "". The println means it will print on that line. Which means it will go to a new line each time
System.out.print(""); //Just using print means it prints out and does not go to a new line
\n - new line
\t - tab
\b - backspace/r - return
\' - Inserts a single quote
\" - Inserts a double quote
\\ - Inserts a backslash
public class FunWithString
{
public static void main(String [] args)
{
System.out.println("This is a String"); //String is an object data type
System.out.print("Roses are Red, ");
System.out.println("Violets are Blue, ");
System.out.println("\tbut I have a \"committment\" issues");
System.out.println("so I think we should be friends, \nat this point in our relationship\\journey.");
System.out.println("This is concatenation " + 24 + 45);
System.out.println("This is adding " + (24+45));
int num1 = 10;
System.out.println("The total is: " + num1 + " boxes.");
String s1 = "The total is: ";
String s2 = "Banana";
String s3 = "Apple";
String s4 = "Orange";
String s6 = "Apple";
System.out.println(s2 + s3);
System.out.println(s3.concat(s4));
System.out.println(s4.length());
System.out.println(s4.substring(1,4));
String s5 = s4.substring(1, 2);
System.out.println(s5);
char c1 = s4.charAt(1);
System.out.println(c1);
System.out.println(!(s4.equals(s6)));
s4 = s4.toUpperCase();
s3 = s3.toLowerCase();
}
}
public class Class1
{//Start class
public static void main (String[] args)
{//Start main
System.out.print("Hellow World!");
System.out.println("Yay!");
//Integer Data Type - Primitive Data type
// 4 integer data types - byte, short, int, long ///////////////////////////////
byte b1; //assigned
b1 = 0; //initialized //256
short s1 = 0; //assigned and initialized
int num1 = 0;
long dig1 = 0;
int num2 = 0, num3 = 4, num4 = 7;
byte b2, b3 = 10, b4 = 1;
int dayOfWeek = 1; //good variable name
int totalPay = 0;
int NUMBER_OF_WIDGETS = 0;
//Floating Point Variables - Primitive Data Types //////////////////// float, double
float f1 = 0.0F;
double d1 = 0.0D;
int iResult = 0;
double dResult = 0.0;
iResult = 4/3;
dResult = 4/3; //assignment conversion
System.out.println(iResult);
System.out.println(dResult);
dResult = 4.0/3; //Arithmetic Promotion
float fResult = (float)4.0/(float)3.0;
iResult = (int)(4.0/3.0); //casting
System.out.println(dResult);
System.out.println(4.0/3.0);
System.out.println(4.0F/3.0F);
num2 = 4;
num2++; //num 2 = num2 + 1;
System.out.println(num2);
System.out.println(++num2);
System.out.println(num2--);
System.out.println(num2);
System.out.println(--num2);
/*Operations on integers: +, -, *, /, %, ++, --, +=, -= , *=, /= */
num2 = 5;
num2*=3; //num2 = num2 * 3;
System.out.println(num2);
num2-=7; //num2 = num2 - 7;
System.out.println(num2);
num2 %= 3;
System.out.println(num2);
float f2 = 0.0F;
f2 = 1.0F;
System.out.println(f2);
//Primitive Data Type: boolean
boolean flag = true;
boolean bool1 = false, boo2;
/*boolean operators: == "equal to"
* != "not equal"
* && "and"
* ! "not"
* || "or"
* > "greater than"
* < "less than"
* <= "less than or equal to"
* >= "greater than or equal to"
*/
//Primitive Data type: character
char c1 = 'a';
char c2 = 'A',c3,c4='#';
//Operations with characters: <, >, <=, >=, =, !=
System.out.println('a'=='A';
}//End main
}//End class
//End file
import java.util.Scanner;//imports the scanner class
import java.text.DecimalFormat;//imports the decimal formatter
public class UserInput
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);//Declares the Scanner in scan
System.out.println("Enter a number: ");
int num = scan.nextInt();//so scan.nextInt takes in an integer and stores it in num
scan.nextLine();//takes in a string
System.out.println("What is your name?");
String name = scan.nextLine();//takes in the string and stores it in name
System.out.println("Enter a decimal:");
double dec = scan.nextDouble();//takes in the decimal and stores it in dec
System.out.println("num = " + num + ", name = " + name + ", and dec = " + dec);//prints out all the things that were entered by the user
DecimalFormat decFormat = new DecimalFormat("0.00");//2.00, it will always put .00
//("0.##") will put 0.number
//("0000") = 0001 when 1 is entered
/*f2 = (float)4/5 = 0.8
f2 = (float)(4/5) = 0.0
import java.text.NumberFormat;
NumberFormat percent = NumberFormat.getPercentInstance();
*/
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.