Translate
Sunday, 22 April 2018
Saturday, 16 December 2017
We count 35 heads and 94 legs among the chickens and rabbits in a farm. How many rabbits and how many chickens do we have?
public class ChickenAndRabbits
{
public static void main(String arga[])
{
int a=35;
int b=94;
int c=a*2;
int d=(b-c)/2;
System.out.println("RABBITS :"+d);
int e=a-d;
System.out.println("CHICKENS :+e);
}
}
OUTPUT
RABBITS 12
CHICKENS 23
Sunday, 10 December 2017
java program area
import java.util.Scanner;
public class Parallelogram
{
public static void main(String[] args)
{
int a, b,area;
Scanner s = new Scanner(System.in);
System.out.print("Enter the base of parallelogram:");
a = s.nextInt();
System.out.print("Enter the height of the parallelogram:");
b = s.nextInt();
area = a * b;
System.out.println("Area of parallelogram:"+area);
}
}
Output:
Enter the base of parallelogram:5
Enter the height of the parallelogram:6
Area of parallelogram:30
Pattern in Java
Pattern in Java
class NumberPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
User code
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Thursday, 30 November 2017
Wednesday, 22 November 2017
font in css
<!DOCTYPE html>
<html>
<head>
<title>List Style</title>
<style>
.ul1 {
list-style-type: circle;
}
.ul2 {
list-style-type: square;
}
.ol1 {
list-style-type: upper-roman;
}
.ol2 {
list-style-type: lower-alpha;
}
</style>
</head>
<body>
<p>Example of unordered lists:</p>
<ul class="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="ul2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<p>Example of ordered lists:</p>
<ol class="ol1">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="ol2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol> <ol class="ol2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
List Style css
<!DOCTYPE html>
<html>
<head>
<title>List Style</title>
<style>
.ul1 {
list-style-type: circle;
}
.ul2 {
list-style-type: square;
}
.ol1 {
list-style-type: upper-roman;
}
.ol2 {
list-style-type: lower-alpha;
}
</style>
</head>
<body>
<p>Example of unordered lists:</p>
<ul class="ul1">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="ul2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<p>Example of ordered lists:</p>
<ol class="ol1">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="ol2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol> <ol class="ol2">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
Saturday, 18 November 2017
text and background color css
<!DOCTYPE html>
<html>
<head>
<title>Background and text color</title>
<style>
.clr_cls {
background-color: red;
color: yellow;
}
</style>
</head>
<body>
<div class="clr_cls">
Mafasict
</div>
</body>
</html>
Friday, 17 November 2017
Java while loop example
While Loop Example
import java.util.Scanner;
class WhileLoop {
public static void main(String[] args) {
int n;
Scanner input = new Scanner(System.in);
System.out.println("Input an integer");
while ((n = input.nextInt()) != 0) {
System.out.println("You entered " + n);
System.out.println("Input an integer");
}
System.out.println("Out of loop");
}
}
Input an integer
7
You entered 7
Input an integer
-2
You entered -2
Input an integer
9546
You entered 9546
Input an inte
ger 0
Out of loop
Wednesday, 15 November 2017
Java 1st program
First Program
class Simple {
public static void main (string args []) {
System.out.println ("Hello Java");
}
}
save this file as Simple.java
To compile: javac Simple.java
To execute: java Simple
It will give output as Hello Java
Let's see what this is:
class keyword is used to declare a class in java.
Public keyword is an access modifier which represents visibility, it means it is visible to all.
static is a keyword, if we declare any method as static, it is known as static method. The main method is executed by the JVM, it does not require the object to invoke the main method. So it saves memory.
The void is the return type of method, it means it does not return any value.
main is a entry point of the program. Execution of programs starts from main. It is called by Runtime System
String [] args is used for command line argument. We will learn it later.
System.out.println () is used print statement.
Monday, 13 November 2017
Java switch statement
5.2 Switch statement
A switch statement is used instead of nested if...else statements. It is multiple branch decision statement.
A switch statement tests a variable with list of values for equivalence. Each value is called a case. The case value must be a constant i.
SYNTAX
switch(expression){
case constant:
//sequence of optional statements
break; //optional
case constant:
//sequence of optional statements
break; //optional
.
.
.
default : //optional
//sequence of optional statements
}
Individual case keyword and a semi-colon (:) is used for each constant.
Switch tool is used for skipping to particular case, after jumping to that case it will execute all statements from cases beneath that case this is called as ''Fall Through''.
In the example below, for example, if the value 2 is entered, then the program will print two one something else!
switch(i)
{
case 4: System.out.println(''four'');
break;
case 3: System.out.println(''three'');
break;
case 2: System.out.println(''two'');
case 1: System.out.println(''one'');
default: System.out.println(''something else!'');
}
To avoid fall through, the break statements are necessary to exit the switch.
If value 4 is entered, then in case 4 it will just print four and ends the switch.
The default label is non-compulsory, It is used for cases that are not present.
Subscribe to:
Posts (Atom)
Featured post
check box
<!DOCTYPE html> <html> <head> <title>Check Box</title> </head> <body> <input ty...
-
<!DOCTYPE html> <html> <head> <title>List Style</title> <style> .ul1 { list-...
-
public class ChickenAndRabbits { public static void main(String arga[]) { int a=35; int b=94; int c=a*2; int d=(b-c)/2; System.out.println(...