forked from fineanmol/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java Practice Programs for Beginners
- Loading branch information
1 parent
a9d6a4b
commit b5a6789
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Fruits { | ||
public void VariousFruits() { | ||
System.out.println("The various fruits are: "); | ||
} | ||
} | ||
class Apple extends Fruits { | ||
public void VariousFruits() { | ||
System.out.println("Apple is a sweet fruit!"); | ||
} | ||
} | ||
class Mango extends Fruits { | ||
public void VariousFruits() { | ||
System.out.println("Mango is my favourite fruit!"); | ||
} | ||
} | ||
class Banana extends Fruits { | ||
public void VariousFruits() { | ||
System.out.println("I don't like bananas!"); | ||
} | ||
} | ||
class Fruitshop { | ||
public static void main(String[] args) { | ||
Fruits myapple = new Fruits(); | ||
Fruits mymango = new Fruits(); | ||
Fruits mybanana = new Fruits(); | ||
myapple.VariousFruits(); | ||
mymango.VariousFruits(); | ||
mybanana.VariousFruits(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
abstract class VegetableShop { | ||
public abstract void Thanks(); | ||
public void Onion() { | ||
System.out.println("The cost of 1 kg of onion is Rs. 30"); | ||
} | ||
public void Chilli() { | ||
System.out.println("The cost of 1 kg of chilli is Rs. 60"); | ||
} | ||
public void Tomato() { | ||
System.out.println("The cost of 1 kg of tomato is Rs. 55"); | ||
} | ||
public void Brinjal() { | ||
System.out.println("The cost of 1 kg of brinjal is Rs. 50"); | ||
} | ||
public void Ladyfinger() { | ||
System.out.println("The cost of 1 kg of Ladyfinger is Rs. 40"); | ||
} | ||
public void Shoppee() { | ||
System.out.println("How many Kgs do you need?"); | ||
System.out.println("The cost of 2 kgs of brinjal is Rs. 100"); | ||
} | ||
} | ||
class Run extends VegetableShop { | ||
public void Thanks() { | ||
System.out.println("Thank you for shopping with us! Please come back!"); | ||
} | ||
} | ||
class Green { | ||
public static void main(String[] args) { | ||
Run myobj = new Run(); | ||
myobj.Onion(); | ||
myobj.Chilli(); | ||
myobj.Tomato(); | ||
myobj.Brinjal(); | ||
myobj.Ladyfinger(); | ||
myobj.Shoppee(); | ||
myobj.Thanks(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class area { | ||
public static void main(String args[]) { | ||
int r = 6; | ||
double a, c; | ||
a = 3.14 * r * r; | ||
c = 2 * 3.14 * r; | ||
System.out.println("The area of the circle is" + " "+ a); | ||
System.out.println("The circumference of the circle is" + " "+ c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import javax.swing.JOptionPane; | ||
class perfect { | ||
public static void main(String[] args) { | ||
int i=1, n; | ||
String s1 = JOptionPane.showInputDialog(null, "Enter your number"); | ||
n = Integer.parseInt(s1); | ||
while(i<=n){ | ||
if(n % i == 0) { | ||
System.out.println(i); | ||
i++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* | ||
import javax.swing.JoptionPane; | ||
class solution{ | ||
public static void main(String args[]){ | ||
String s = JoptionPane.showInputDialog(null, "Enter your number"); | ||
n = Integer.parseInt(s); | ||
for(i=1; i<=n; i++) { | ||
System.out.println(i); | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import javax.swing.JOptionPane; | ||
class solution{ | ||
public static void main(String args[]){ | ||
String s = JOptionPane.showInputDialog(null, "Enter your number"); | ||
int n = Integer.parseInt(s); | ||
for(int i=1; i<=n; i++) { | ||
if (n % i == 0){ | ||
System.out.println(i); | ||
} | ||
} | ||
} | ||
} |