using class in java
Java
public class HelloWorld {
public static void main(String[] args) {
// how to use class in java
class User{
int score;
// method that can be used outside the class
public boolean hasWon(){
if(score >= 100){
return true;
} else {
return false;
}
}
}
User dave = new User();
dave.score = 20;
System.out.println(dave.hasWon());
}
}
public class HelloWorld {
public static void main(String[] args) {
// how to use class in java
class User{
int score;
}
User dave = new User();
dave.score = 20;
System.out.println(dave.score);
}
}
public class HelloWorld {
public static void main(String[] args) {
class Number{
int number;
public boolean isPos(){
if(number > 0){
return true;
} else {
return false;
}
}
}
Number myNumber = new Number();
myNumber.number = 7;
if(myNumber.isPos()){
System.out.println(myNumber.number + " is positive!!!");
} else {
System.out.println(myNumber.number + " is not positive!!!");
}
}
}
public class MyClass {
int x = 5;
public static void main(String[] args) {
MyClass myObj = new MyClass();
System.out.println(myObj.x);
}
}
class Number {
int number;
// square numbers
public boolean isSquare(){
double squareRoot = Math.sqrt(number);
if(squareRoot == Math.floor(squareRoot))
{
return true;
} else {
return false;
}
}
// triangular numbers
public boolean isTriangular(){
int x = 1;
int triangularNumber = 1;
while(triangularNumber < number){
x++;
triangularNumber = triangularNumber + x;
}
if(triangularNumber == number){
return true;
} else {
return false;
}
}
}
// testing
Number myNumber = new Number();
myNumber.number = 16;
System.out.println(myNumber.isSquare());
Also in Java:
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- java split string on two or more spaces except for words in quotes
- Category
- Java
- Title
- java script zip function
- Category
- Java
- Title
- how to format a double in java to 2 decimal places
- Category
- Java
- Title
- java "->"
- Category
- Java
- Title
- number to char java
- Category
- Java
- Title
- catch array out of bounds exception java
- Category
- Java
- Title
- null pointer exception java
- Category
- Java
- Title
- get host from request object java
- Category
- Java
- Title
- if statement java
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- java program to display characters from a to z using loop
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- java random number
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- java mysql springboot jpa stackoverflow
- Category
- Java
- Title
- java literals w3schools
- Category
- Java
- Title
- prendere valore da tastiera java
- Category
- Java
- Title
- how to do for each in java
- Category
- Java
- Title
- How to print in console java
- Category
- Java
- Title
- copy array in java
- Category
- Java
- Title
- java - get open ports
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- how to open a text file in java
- Category
- Java
- Title
- how to make a dictionary in java
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- reading string after double in java
- Category
- Java
- Title
- how to run java program in linux server
- Category
- Java
- Title
- Java app development
- Category
- Java
- Title
- java random number between 100 and 999
- Category
- Java
- Title
- how to print hello world in java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- change number into array in java
- Category
- Java
- Title
- calculating the percentile in java
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- jar file not running after being compiled
- Category
- Java
- Title
- how to get length of integer in java
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- initialiser une arraylist
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- android dynamically create layer-list with item and shape site:stackoverflow.com
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- java mockito any string import
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- in java how to convert string to integer
- Category
- Java
- Title
- connect 2 package in android
- Category
- Java
- Title
- java divisible by operator
- Category
- Java
- Title
- counting the number of characters in a string java
- Category
- Java
- Title
- system.out.println shortcut
- Category
- Java
- Title
- how to change tablayout current view position in android
- Category
- Java
- Title
- numberformatexception
- Category
- Java
- Title
- java list get first element
- Category
- Java
- Title
- java replace all xml decoding
- Category
- Java
- Title
- java read file from command line argument
- Category
- Java
- Title
- loop java
- Category
- Java
- Title
- java s3 images
- Category
- Java
- Title
- how to byheart faster
- Category
- Java
- Title
- j
- Category
- Java
- Title
- fibonacci sequence java
- Category
- Java
- Title
- java switch multiple values
- Category
- Java
- Title
- java for each
- Category
- Java
- Title
- java script using navigator.useragent to detect the browse
- Category
- Java
- Title
- how to initialize an array in java
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- java variable string
- Category
- Java
- Title
- android dismiss keyboard
- Category
- Java
- Title
- java check if element exists in array
- Category
- Java
- Title
- Java array nested equals
- Category
- Java
- Title
- executors java
- Category
- Java
- Title
- serialversionuid java
- Category
- Java
- Title
- compare list from db and list from request
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- que es un length en java
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- java enum
- Category
- Java
- Title
- http client java
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- java arraylist to string
- Category
- Java
- Title
- could not initialize defaultkotlinsourcesetkt intelij
- Category
- Java
- Title
- java double 2 decimal
- Category
- Java
- Title
- how to echo java_home in windows cmd
- Category
- Java
- Title
- java command line arguments
- Category
- Java
- Title
- color from hex code flutter
- Category
- Java
- Title
- java read file text
- Category
- Java
- Title
- stackoverflow java enum with constructor
- Category
- Java
- Title
- java display message
- Category
- Java
- Title
- loop through array java
- Category
- Java
- Title
- how to find the total of the products added to the shopping cart in java program
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- java arraylist to array
- Category
- Java
- Title
- time conversion solution
- Category
- Java
- Title
- for loop java
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- how to interrupt a void java
- Category
- Java