Simple Java Code for Star Pattern.
Output:
java .\StarPatternUsingNastedLoops.java
7
*
**
***
****
*****
******
*******
Simple Java Code for Star Pattern.
Output:
java .\StarPatternUsingNastedLoops.java
7
*
**
***
****
*****
******
*******
filename = MultiplicationTable.java
filename: MultiTest.java
filename: printMultiplicationTable.java
Output of program:
Loops> java .\MultiplicationTable.java
Enter number: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
import java.util.Scanner;
public class ReadSetofIntegersPrintsSumofEvenAndOddIntegers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number, chioce, evenSum = 0, OddSum = 0;
do {
System.out.print("Enter the number ");
number = sc.nextInt();
if (number % 2 == 0) {
evenSum += number;
} else {
OddSum += number;
}
System.out.println("Do you want to continue? Press 1 for yes or 0 for no");
chioce = sc.nextInt();
} while (chioce == 1);
System.out.println("Sum of even numbers: " + evenSum);
System.out.println("Sum of odd numbers: " + OddSum);
}
}
import java.util.Scanner;
public class PrimeNumberCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean isPrime = true;
for (int i = 2; i <= n - 1; i++) {
if (n % i == 0) { // n is multiple of i (i not equal to 1 or n)
isPrime = false;
}
}
if (isPrime == true) {
System.out.print(n + " is prime number");
} else {
System.out.print(n + " is not prime number");
}
}
}
import java.util.Scanner;
public class KeepEnteringNumbersTillUserEntersMultipleOf {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
do {
System.out.println("Enter your Number : ");
int num = sc.nextInt();
if (num % 10 == 0) {
break;
}
System.out.println(num);
} while (true);
}
}
import java.util.Scanner;
public class ReverseTheGivennNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int rev = 0;
while (num > 0) {
int lastDigit = num % 10;
rev = (rev * 10) + lastDigit;
num /= 10;
}
System.out.println(rev);
}
}
import java.util.Scanner;
public class ReverseOfNumber {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in); // use for input from user
int num = sc.nextInt();
// int num = 10899;
while (num > 0) {
int lastDigit = num % 10;
System.out.print(lastDigit);
num = num / 10; // n/10;
}
System.out.println();
}
}
import java.util.*;
//Print Square pattern
public class squarePattern {
public static void main(String args[]) {
// for (int lines = 1; lines <= 4; lines++)
// System.out.println("****");
int lines = 1;
while (lines <= 4) {
System.out.println("****");
lines++;
}
}
}
import java.util.Scanner;
// Sum of first N natural Numbers , Naymul Islam CSE 18
public class sumofN {
public static void main(String args[]) {
System.out.print("Enter Natural Number: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0;
int i = 1;
while (i <= n) {
sum += i;
i++;
}
// System.out.println(sum);
System.out.println("Sum of first " + n + " natural Numbers: " + sum);
}
}
import java.util.Scanner;
public class WhileLoop {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int counter = 1;
while (counter <= n) {
System.out.println("I Love You " + counter);
counter++;
}
System.out.println(n + " times I love you print.");
}
}
import java.util.Scanner;
public class calculator {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a :");
int a = sc.nextInt();
System.out.println("Enter b :");
int b = sc.nextInt();
System.out.println("Enter Operator");
char operator = sc.next().charAt(0);
switch (operator) {
case '+':
System.out.println(a + b);
break;
case '-':
System.out.println(a - b);
break;
case '*':
System.out.println(a * b);
break;
case '/':
System.out.println(a / b);
break;
case '%':
System.out.println(a % b);
break;
default:
System.out.println("Wrong Operator");
break;
}
}
}
Code:
import java.util.Scanner;
public class LeapYear {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Input the year: ");
int year = sc.nextInt();
boolean x = (year % 4) == 0;
boolean y = (year % 100) != 0;
boolean z = ((year % 100 == 0) && (year % 400 == 0));
if (x && (y || z)) {
System.out.println(year + " is a leap year");
} else {
System.out.println(year + " is not a leap year");
}
}
}
import java.util.Scanner;
Write a C program to Draw the Flag of Norway.
Function Name : Draw the Flag of Norway
Purpose : In this Program we will learn how to draw the Norway flag on the output screen in c programming language by using c graphics library functions.
Code :
#include<graphics.h> #include<conio.h> main() { int driver,mode; driver=DETECT; mode=0; initgraph(&driver,&mode,"c:\\tc\\bgi"); initgraph(&driver,&mode,""); setbkcolor(WHITE); setcolor(WHITE); rectangle(150,40,430,180); setfillstyle(1,RED); floodfill(160,50,WHITE); setfillstyle(1,WHITE); bar(150,90,430,130); setfillstyle(1,WHITE); bar(230,40,270,180); setfillstyle(1,BLUE); bar(150,100,430,120); setfillstyle(1,BLUE); bar(240,40,260,180); getch(); }
Output:
Code of: Max Sub Array Sum: Kadane's Algorithm. public class MaxSubArraySumKadanesALgorithm { public static void Kadane ( int ...