0% found this document useful (0 votes)
18 views

Computer Project 9 g

jj jn

Uploaded by

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

Computer Project 9 g

jj jn

Uploaded by

ishanaaaaaa189
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

ACKNOWLEDGEMENT

GOOD MORNING AND JAIJAGAT

I would like to express my sincere gratitude and


appreciation to all those who have contributed to the
successful completion of my computer project. This
endeavor would not have been possible without the
support, guidance, and encouragement.
First and foremost, I would like to extend my heartfelt
thanks to my teacher, Ms. Manju Rawat ma’am, for
her invaluable guidance and unwavering support
throughout the project.
I am also grateful to my brother, for his support
contributions . his insights and assistance
significantly enriched the project, and I am thankful
for his willingness to share their knowledge.
QUESTION-WAP IN JAVA TO ENTER A NO. AND CHECK IF IT IS A NIVEN NO.
OR NOT
import java.util.*;
OUTPUT-
class niven

{public static void main(String args[])

{Scanner sc=new Scanner(System.in);

System.out.println("enter a number");

int n=sc.nextInt();

int s=0;

int d=0;

int k=0;

int i=n;

while(i!=0)

{ d=n%10;

s=s+d;

i/=10;

}if(n%s==0)

System.out.println("it is niven");

else

System.out.println("not niven"); }

-VARIABLE DESCRIPTION TABLE-

VARIABLE NAME DATA TYPE DESCRIPTION


S int For calculating sum of digits

i int For storing value of number

n int For entering the value of number


from user
d Int For chopping digits
QUESTION-WAP IN JAVA TO ENTER A NUMBER AND PRINT THE GREATEST
DIGIT
import java.util.*;
OUTPUT-
public class GreatestDigit

{public static void main(String args[])

{Scanner sc = new Scanner(System.in);

System.out.print("Enter a number with at least two digits: ");

int n= sc.nextInt();//1931

int greatestDigit = 0;

int r;

while(n>0)

{r= n%10;//1,3,9,1

if(r>greatestDigit)

{greatestDigit = r;//1,3,9

}n=n/10;//193,19,1,0

}System.out.println("The greatest digit is: " + greatestDigit);

-VARIABLE DESCRIPTION TABLE-

VARIABLE NAME DATA TYPE DESCRIPTION


greatestDigit int For comparing with greatest digit

r int For chopping digits

n int For entering the value of number


from user
QUESTION-WAP IN JAVA TO ENTER A NUMBER AND CHECK IF IT IS A SPY
NO.
import java.util.*;
OUTPUT-
class SpyNumber {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number"); // 1124

int n = sc.nextInt(); // 1124

int p = 1;

int s = 0;

int d;

do {

d = n % 10; // 4, 2, 1, 1

p *= d; // 4, 8, 8, 8

s += d; // 4, 6, 7, 8

n /= 10;

} while (n != 0);

if (p == s)

System.out.println("Spy");

else

System.out.println("Not Spy"); }}

-VARIABLE DESCRIPTION TABLE-

VARIABLE NAME DATA TYPE DESCRIPTION


s int For storing the sum of digits

p int For storing the product of digits

n int For entering the value of number


from user
d int For chopping out digits
QUESTION-WAP IN JAVA TO ENTER A NUMBER AND CHECK IF IT IS A
PALINDROME NO.
import java.util.*;
OUTPUT-
class Palindrome {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number");

int n = sc.nextInt(); // 121

int d, r = 0;

do {

d = n % 10;

r = (r * 10) + d; // 1, 12, 121

n /= 10;

} while (n != 0);

if (r == n)

System.out.println("Palindrome.");

else

System.out.println("Not Palindrome"); }}

-VARIABLE DESCRIPTION TABLE-


VARIABLE NAME DATA TYPE DESCRIPTION
r int For storing the reversed no.

d int For chopping out digits

n int For entering the value of number


from user
QUESTION-WAP IN JAVA TO PRINT THE FOLLOWING PATTERN
1**** class level2patternnn
OUTPUT-
22***
{
333**
public static void main(String args[]) {
4444*
for(int i=1;i<=5;i++) {
55555
for(int j=1;j<=5;j++) {

if(i<j)

System.out.print("*");

else

System.out.print(i);

System.out.println();

} }}

VARIABLE NAME DATA TYPE DESCRIPTION


i int For storing the reversed no.

j int For chopping out digits


QUESTION-WRITE A MENU DRIVEN PROGRAM IN JAVA ACCORDINGLY
import java.util.*;

class menudrivenpattern

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter your choice\npress 1 for wordpattern\npress 2 for printing 10 no.s between n and n-
1\npress 3 for printing all"+

"armstrong no.s in a given range");

int choice=sc.nextInt();

switch(choice)

case 1:System.out.println("enter a word");

String s=sc.next();

int l=s.length();

for(int i=l;i>0;i--)

for(int j=0;j<i;j++)

System.out.print(s.charAt(j)+" ");

System.out.println();

break;

case 2:System.out.println("enter the value of n");

int n=sc.nextInt();///10

System.out.println("enter the value of m");

int m=sc.nextInt();///7

int range=n-m;//3

for(int i=1;i<=10;i++)

System.out.println(range*Math.random()+m);
for(int i=1;i<=10;i++)

System.out.println(range*Math.random()+m);

break;

case 3:

for (int k = 1; k <= 1000000; k++)

int count=1;

int i;

for(i=k;i>0;i/=10) //i=25

count=count*10;

if ((k*k) % count == k)

System.out.println(k);

break;

OUTPUT-
QUESTION-WAP IN JAVA TO PRINT TABLE FROM 1-10

import java.util.Scanner;

public class Multiplication{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int i = 1;

while (i <= 10) {

int j = 1;

while (j <= 10) {

System.out.print(i * j + "\t");

j++;

System.out.println();

i++;

}}}

OUTPUT-

VARIABLE NAME DATA TYPE DESCRIPTION


i int For storing the reversed no.

j int For chopping out digits


QUESTION-WAP IN JAVA TO PRINT SUM OF PRIME NO. UPTO N
import java.util.Scanner;

public class SumOfPrimes {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number:");

int num = sc.nextInt();

int sum = 0;

int i = 2;

do {

boolean isPrime = true;

int j = 2;

do {

if (i % j == 0 && i != j) {

isPrime = false;

break;

j++;

} while (j <= i / 2);

if (isPrime) {

sum += i; }

i++;

} while (i <= num);

System.out.println("Sum of prime numbers up to " + num + " is: " + sum);

}}
Program 4: Print a Hollow Square Pattern

import java.util.Scanner;

public class HollowSquarePattern {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter the size of the square:");

int size = sc.nextInt();

int row = 1;

do {

int col = 1;

do {

if (row == 1 || row == size || col == 1 || col == size) {

System.out.print("* ");

} else {

System.out.print(" ");

col++;

} while (col <= size);

System.out.println();

row++;

} while (row <= size);}}


Program 2: Pyramid Pattern

This program prints a pyramid pattern using nested while loops.

import java.util.Scanner;

public class PyramidPattern {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of rows for the pyramid:");

int rows = sc.nextInt();

int i = 1;

while (i <= rows) {

int j = 1;

while (j <= rows - i) {

System.out.print(" "); // Print spaces

j++;}

int k = 1;

while (k <= 2 * i - 1) {
OUTPUT-
System.out.print("* ");

k++;

}System.out.println();

i++;

} }}

VARIABLE NAME DATA TYPE DESCRIPTION


i int For storing the reversed no.

K int For chopping out digits

J int For printing spaces


COMPUTER PROJECT
NAME-ISHANA
CLASS-9TH- G
SUBJECT-COMPUTER
SUBJECT TEACHER-MS.MANJU
RAWAT
REMARKS-
………………………………………….

You might also like