Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Java units 4 programming

Rating
-
Sold
-
Pages
35
Uploaded on
12-03-2025
Written in
2024/2025

Lecture notes of 35 pages for the course Java units 4 at Java units 4 (All the best)

Institution
Course

Content preview

JAVA PROGRAMS
Display odd numbers between 1 -100
class OddNumber {
public static void main(String args[]) {
System.out.println("The Odd Numbers are:");
for (int i = 1; i <= 100; i++) {
if (i % 2 != 0) {
System.out.print(i + " ");
}
}
}
}

Sum of odd numbers between 1 -100
class SumOfNum
{
public static void main(String args[])
{
int sum = 0;
for (int i = 1; i <= 100; i++)
{
if (i % 2 != 0)
{
sum = sum + i;
}
}
System.out.println("The Sum Of 100 Odd Numbers are:" + sum);
}
}

Total number of odd numbers between 1 -100
class TotalNumOfOddNum
{
public static void main(String args[])
{
int count = 0;
for(int i = 1;i <= 100;i++)
{
if(i % 2 != 0)
{
count++;
}
}
System.out.println("The Count Of Odd Numbers are:" + count);
}
}

,Find sum of first n numbers
class SumOfNum
{
public static void main(String args[])
{
int sum = 0;
int n=10;
for(int i = 1;i <= n;i++)
{
sum = sum + i;
}
System.out.println("The Sum Of "+n+" Numbers are:" + sum);
}
}
Find the sum of the digits of a number
public class DigitsSum
{

public static void main(String[] args)
{
int num=251025, rem = 0, sum = 0, temp;
temp = num;

while (num > 0)
{
rem = num % 10;
sum = sum + rem;
num = num / 10;
}

System.out.print("Sum of Digits of " + temp + " is " + sum);
}

}
Calculate electricity bill
public class ElectricBill
{
public static void main(String args[])
{
int units = 123;
int bill = 0;

if (units > 100)
{
if (units >= 200)
{
if (units > 300)
{
bill = units * 8;
}
else

, bill = units * 6;
}
else
bill = units * 5;
}

System.out.println("CHENNAI ELECTRICITY LTD, CHENNAI");
System.out.println("Units Consumed : " + units);
System.out.println("Total Bill : " + bill);
}
}
Java program to find Armstrong number
public class ArmstrongNumber
{
public static void main(String args[])
{
int n, arg, sum = 0, r;

n = 153; // input value
arg = n;
for (int i = 1; i < n; i++)
{
while (n > 0)
{
r = n % 10;
sum = sum + (r * r * r);
n = n / 10;

}

}
if (arg == sum)
{
System.out.println("Given number is armstrong number: " + arg);
}
else
{
System.out.println("Given number is not armstrong number: " + arg);
}
}

}
Program to print Armstrong number between 1 to 1000
public class ArmstrongNumbers
{

public static void main(String[] args)
{
int num,rem,limit=1000, sum = 0;
System.out.print("Armstrong numbers from 1 to N:");
for (int i = 1; i <= limit; i++)

, {
num = i;
while (num > 0)
{
rem = num % 10;
sum = sum + (rem*rem*rem);
num = num / 10;
}

if (sum == i)
{
System.out.print(i + " ");
}
sum = 0;
}

}

}
Print given number in words
public class NumberToWords
{

public void pw(int n, String ch)
{
String one[] = { " ", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", "
Nine", " Ten"," Eleven", " Twelve", " Thirteen", " Fourteen", "Fifteen", " Sixteen", " Seventeen",
" Eighteen"," Nineteen" };

String ten[] = { " ", " ", " Twenty", " Thirty", " Forty", " Fifty", " Sixty", "Seventy", " Eighty",
" Ninety" };

if (n > 19)
{
System.out.print(ten[n / 10] + " " + one[n % 10]);
}
else
{
System.out.print(one[n]);
}
if (n > 0)
System.out.print(ch);
}

public static void main(String[] args)
{

int n=28;
System.out.print(n);
if (n <= 0)
{

Written for

Course

Document information

Uploaded on
March 12, 2025
Number of pages
35
Written in
2024/2025
Type
Class notes
Professor(s)
Prem
Contains
All classes

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
premkumarethicalhacker

Get to know the seller

Seller avatar
premkumarethicalhacker Mannar thirumalai naciker college
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
1
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions