- Information
- AI Chat
Javaprograms - this ia a list of typical java programs that can be asked in tests and are helpful
Java programming (CSC1016S)
University of Cape Town
Recommended for you
Preview text
JAVA PROGRAMS Display odd numbers between 1 class OddNumber public static void main(String Numbers for System.out(i Sum of odd numbers between class SumOfNum public static void main(String int for sum sum Sum Of 100 Odd Numbers Total number of odd numbers between class TotalNumOfOddNum public static void main(String int count Count Of Odd Numbers JAVA PROGRAMS Display odd numbers between 1 class OddNumber public static void main(String Numbers for System.out(i Sum of odd numbers between class SumOfNum public static void main(String int for sum sum Sum Of 100 Odd Numbers Total number of odd numbers between class TotalNumOfOddNum public static void main(String int count Count Of Odd Numbers Find sum of first n numbers class SumOfNum public static void main(String int sum int sum sum Sum Of Numbers Find the sum of the digits of a number public class DigitsSum public static void args) int rem 0, temp while (num rem num sum sum num num of Digits of temp Calculate electricity bill public class ElectricBill public static void main(String int units int bill if (units 100) if (units 200) if (units 300) bill units else Find sum of first n numbers class SumOfNum public static void main(String int sum int sum sum Sum Of Numbers Find the sum of the digits of a number public class DigitsSum public static void args) int rem 0, temp while (num rem num sum sum num num of Digits of temp Calculate electricity bill public class ElectricBill public static void main(String int units int bill if (units 100) if (units 200) if (units 300) bill units else num while (num 0) rem num sum sum num num if (sum Print given number in words public class NumberToWords public void pw(int n, String ch) String if (n 19) else if (n 0 ) public static void args) int if (n num while (num 0) rem num sum sum num num if (sum Print given number in words public class NumberToWords public void pw(int n, String ch) String if (n 19) else if (n 0 ) public static void args) int if (n numbers greater than else NumberToWords a new a((n a((n 100), a((n 100), Program to check the given number is Palindrome or not public class PalindromeNumberCheck public static void args) int while (n 0) rev rev 10 if (rev The given no is palindrome else given no is not palindrome Program to print palindrome number upto N numbers public class PalindromeUptoN public static void args) int n, b, rev int numbers greater than else NumberToWords a new a((n a((n 100), a((n 100), Program to check the given number is Palindrome or not public class PalindromeNumberCheck public static void args) int while (n 0) rev rev 10 if (rev The given no is palindrome else given no is not palindrome Program to print palindrome number upto N numbers public class PalindromeUptoN public static void args) int n, b, rev int public class PyramidPattern1 public static void args) int for(int for(int public class PyramidPattern2 public static void main(String int public class PyramidPattern1 public static void args) int for(int for(int public class PyramidPattern2 public static void main(String int public class DifferentPatternPrograms1 public static void main(String int Scanner the n public class DifferentPatternPrograms1 public static void main(String int Scanner the n Print numbers in sequence way public class PatternNumberSequence public static void args) int int b int int 347 7 5 12 12 6 18 18 7 25 25 8 33 33 9 42 42 10 52 52 11 63 Print numbers in triangle and pyramid vice 1 121 12321 1234321 123454321 import public class PatternNuberPyramidPrevRev public static void main(String int int Scanner SC new the N n for (inti while (s Print numbers in sequence way public class PatternNumberSequence public static void args) int int b int int 347 7 5 12 12 6 18 18 7 25 25 8 33 33 9 42 42 10 52 52 11 63 Print numbers in triangle and pyramid vice 1 121 12321 1234321 123454321 import public class PatternNuberPyramidPrevRev public static void main(String int int Scanner SC new the N n for (inti while (s while (s 1 23 456 78910 11 12 13 14 15 public class PatternNumberPyramidUptoN public static void main(String nt for for 1 12 123 1234 12345 import public class PatternNumberPyramid public static void main(String while (s 1 23 456 78910 11 12 13 14 15 public class PatternNumberPyramidUptoN public static void main(String nt for for 1 12 123 1234 12345 import public class PatternNumberPyramid public static void main(String import public class PatternNumberPyramidRev public static void main(String int i, j, k, n, Scanner SC : new the n n for for (j )), for for int 1 212 32123 4321234 543212345 Print different patterns using stars import public class Star1 public static void main(String import public class PatternNumberPyramidRev public static void main(String int i, j, k, n, Scanner SC : new the n n for for (j )), for for int 1 212 32123 4321234 543212345 Print different patterns using stars import public class Star1 public static void main(String int i, j, many row you want Scanner sc new t for for public class Star3 public static void x) int i,j,k,n for for for for int i, j, many row you want Scanner sc new t for for public class Star3 public static void x) int i,j,k,n for for for for The Array Element Largest Number Program to find second largest number in an array public class SecondLargest public static void args) int 14, 46,4 47, 86, 92, 52, 48, 36, 66, 85 int largest int secondLargest array for for (int i else if secondLargest) largest number Find largest and smallest number in an array in java public class LargestSmallest public static void args) int new 23, 34, 13, 64, 72, 90, 10, 15, 9,27 ) int min assume first elements as smallest number int max assume first elements as largest number for (int i iterate for loop from arrays 1st index (second element) if max) The Array Element Largest Number Program to find second largest number in an array public class SecondLargest public static void args) int 14, 46,4 47, 86, 92, 52, 48, 36, 66, 85 int largest int secondLargest array for for (int i else if secondLargest) largest number Find largest and smallest number in an array in java public class LargestSmallest public static void args) int new 23, 34, 13, 64, 72, 90, 10, 15, 9,27 ) int min assume first elements as smallest number int max assume first elements as largest number for (int i iterate for loop from arrays 1st index (second element) if max) max if Number in a given array is : Number in a given array is Program to find largest and second largest in an array public class LargestAndSecondLargest public static void args) int 5, 34, 78, 2, 45, 1, ,99,23 int maxOne int maxTwo for (int if maxTwo maxOne else if maxTwo Number: Largest Find the index of the largest number in an array public class LargestNumberIndex public static void args) int 1 12, 44, 23, 56, 23, 78, 13 int max int for max if Number in a given array is : Number in a given array is Program to find largest and second largest in an array public class LargestAndSecondLargest public static void args) int 5, 34, 78, 2, 45, 1, ,99,23 int maxOne int maxTwo for (int if maxTwo maxOne else if maxTwo Number: Largest Find the index of the largest number in an array public class LargestNumberIndex public static void args) int 1 12, 44, 23, 56, 23, 78, 13 int max int for else for (int return public static void main(String intl 10, 10, 10, 12, 12 output for (int i : input1) for (int i : output) Program to print odd and even numbers from an array public class OddEvenArray public static void main(String int S, a 33, 2, 4, 71, 88, 92, for else for (int return public static void main(String intl 10, 10, 10, 12, 12 output for (int i : input1) for (int i : output) Program to print odd and even numbers from an array public class OddEvenArray public static void main(String int S, a 33, 2, 4, 71, 88, 92, for numbers if numbers if Program to add two matrix class MatrixAddition public static void main(String numbers if numbers if Program to add two matrix class MatrixAddition public static void main(String
Javaprograms - this ia a list of typical java programs that can be asked in tests and are helpful
Course: Java programming (CSC1016S)
University: University of Cape Town
- Discover more from: