0% found this document useful (0 votes)
7 views6 pages

Java Programs for Astrology and Patterns

The document contains code for a Java program that takes in a date and month as input and outputs the corresponding astrological sign. It first checks if the date and month inputs are valid, and then uses if/else statements to check the month and date ranges to determine and print the astrological sign.

Uploaded by

Aditya Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Java Programs for Astrology and Patterns

The document contains code for a Java program that takes in a date and month as input and outputs the corresponding astrological sign. It first checks if the date and month inputs are valid, and then uses if/else statements to check the month and date ranges to determine and print the astrological sign.

Uploaded by

Aditya Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

IPL code

import [Link].*;
class MyClass{
public static void main(String [] args){
Scanner sc=new Scanner([Link]);
int date=[Link]();
int mon=[Link]();
if(date>31 ||date<=0)
[Link]("Invalid Date/Month");
else if(mon>12||mon<=0)
[Link]("Invalid Date/Month");
else
{
if(mon==1)
{
if(date>=20)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Aquarius");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Capricorn");
}
else if(mon==2)
{
if(date>=19&&date<29)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Pisces");
else if(date<=19)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Aquarius");
}
else if(mon==3)
{
if(date>=21)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Aries");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Pisces");
}
else if(mon==4)
{
if(date>=20&&date<31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Taurus");
else if(date!=31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Aries");
}
else if(mon==5)
{
if(date>=21)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Gemini");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Taurus");
}
else if(mon==6)
{
if(date>=21&&date<31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Cancer");
else if(date!=31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Gemini");
}
else if(mon==7)
{
if(date>=23)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Leo");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Cancer");
}
else if(mon==8)
{
if(date>=23)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Virgo");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Leo");
}
else if(mon==9)
{
if(date>=23&&date<31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Libra");
else if(date!=31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Virgo");
}
else if(mon==10)
{
if(date>=23)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Scorpio");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+" "+ " Libra");
}
else if(mon==11)
{
if(date>=22&&date<31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Sagittarius");
else if(date!=31)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Scorpio");
}
else if(mon==12)
{
if(date>=22)
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Capricon");
else
[Link]("Astrological sign for"+" "+date+"-"+mon+" " +"is"+ " Sagittarius");
}
}
}
}
Sand clock (Riya decided…)

import [Link].*;
class myClass{
public static void main(String [] args){
Scanner sc=new Scanner([Link]);
int n=[Link]();
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
[Link](" ");
}
int k=i+1;
while(k<=n)
{
[Link](k+" ");
k++;
}
[Link]();
}

for(int i=n-1;i>0;i--)
{
for(int j=1;j<i;j++)
{
[Link](" ");
}
int k=i;
while(k<=n)
{
[Link](k+" ");
k++;
}
[Link]();
}
}
}
Multiplication code (After learning the…)

import [Link].*;
class myClass{
public static void main(String [] args){
Scanner sc=new Scanner([Link]);
int n=[Link]();
int u=((n+1)/2)+1;
int k=0;
if(n%2==0)
{
[Link]("Enter ODD number of rows");
}
else
{
for(int i=1;i<u;i++) {
for (k = 1; k <= i; k++) {
[Link](k * i + " ");
}
[Link]();
}
k=k-2;
for(int q=u;q<n+1;q++)
{
for(int w=1;w<=k;w++)
{
[Link](w*q+" ");

}
k--;
[Link]();
}
}
}
}
Display numbers (Ankit recently enrolled…)

import [Link];
class Harshpattern {
public static void main(String args[]){
Scanner sc=new Scanner([Link]);
int n=[Link]();
int k=1,i,j;
int[][] a=new int[n][n];
for(i=0;i<n;i++){
if(i%2==0){
for(j=i;j<n;j++){
a[j][i]=k;
k++;
}
}
else{
for(j=n-1;j>=i;j--){
a[j][i]=k;
k++;
}
}
}
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
[Link](a[i][j]+" ");
}
[Link]();
}
}
}
Calculator (Seetha, a maths teacher…)

import [Link];
class Harsh {
public static void main(String[] args) {
Scanner reader = new Scanner([Link]);
[Link]("Enter two numbers: ");
double first = [Link]();
double second = [Link]();
char operator = [Link]().charAt(0);
double result;
switch(operator)
{
case '+':
result = first + second;
break;
case '-':
result = first - second;
break;
case '*':
result = first * second;
break;
case '/':
result = first / second;
break;
// operator doesn't match any case constant (+, -, *, /)
default:
}
[Link]("%.1f %c %.1f = %.1f", first, operator, second, result);
}
}

You might also like