Contents: Click for quick access
196. Write a program in java using to print the sum of first ten positive integers.197. Write a program in java to print cube root of an ask number.198. Write a program in java to convert octal number to decimal number.199. Write a program in java to ask number and check whether the given no is prime or not200.Write a program in java to generate the series 1,2,4,8,16… upto 10th term.201. Write a program in java to convert decimal number to binary number.202. Write a program in java to generate the series 50,46,41,35…………7th terms.203. Write a program in java to generate the series 1,4,7,10…………12th terms.204. Write a program in java to print all palindrome numbers from 1 to 200.205. Write a program in java to print all natural numbers from 1 to 100.
I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.
Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US
196. Write a program in java using to print the sum of first ten positive integers.
class PositiveNumber {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum = sum + i;
}
System.out.println("The sum of first ten positive integers is " + sum);
}
}
197. Write a program in java to print cube root of an ask number.
import java.util.Scanner;
class CubeRoot {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your number");
int num = sc.nextInt();
int cube = (int) Math.pow(num, 1 / 3);
System.out.println("The cube root of " + num + " is " + cube);
}
}
198. Write a program in java to convert octal number to decimal number.
import java.util.Scanner;
class OctalToDecimal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your octal number");
int oct = sc.nextInt();
int dec = 0;
int i = 0;
while (oct != 0) {
int rem = oct % 10;
dec = dec + rem * (int) Math.pow(8, i);
i++;
oct = oct / 10;
}
System.out.println("The decimal number is " + dec);
}
}
199. Write a program in java to ask number and check whether the given no is prime or not
import java.util.Scanner;
class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your number");
int num = sc.nextInt();
int flag = 0;
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (flag == 0) {
System.out.println("The number is prime");
} else {
System.out.println("The number is not prime");
}
}
}
200.Write a program in java to generate the series 1,2,4,8,16… upto 10th term.
class Series
{
public static void main(String args[]){
int a = 1;
for (int i = 1; i < 10; i++) {
System.out.print(a+ " ");
a=a*2;
}
}
}
201. Write a program in java to convert decimal number to binary number.
import java.util.Scanner;
class DecimalToBinary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your decimal number");
int dec = sc.nextInt();
int bin = 0;
int i = 0;
while (dec != 0) {
int rem = dec % 2;
bin = bin + rem * (int) Math.pow(10, i);
i++;
dec = dec / 2;
}
System.out.println("The binary number is " + bin);
}
}
202. Write a program in java to generate the series 50,46,41,35…………7th terms.
class Series
{
public static void main(String args[]){
int a = 50;
int b=4;
for (int i = 1; i <= 7; i++) {
System.out.print(a+ " ");
a=a-b;
b=b+1;
}
}
}
203. Write a program in java to generate the series 1,4,7,10…………12th terms.
class Series
{
public static void main(String args[]){
int a = 1;
for (int i = 1; i <= 12; i++) {
System.out.print(a+ " ");
a=a+3;
}
}
}
204. Write a program in java to print all palindrome numbers from 1 to 200.
import java.util.Scanner;
class Palindrome {
public static void main(String[] args) {
for (int i = 1; i <= 200; i++) {
String str = String.valueOf(i);
String rev = "";
for (int j = str.length() - 1; j >= 0; j--) {
rev = rev + str.charAt(j);
}
if (str.equals(rev)) {
System.out.println(str);
}
}
}
}
205. Write a program in java to print all natural numbers from 1 to 100.
class Series
{
public static void main(String args[]){
for (int i = 1; i <= 100; i++) {
System.out.print(i+ " ");
}
}
}