The document contains 3 Java programs:
1) A program to display the first ten terms of the series 1, 12, 123, 1234 etc. by using nested for loops.
2) A program that takes numbers from user input, calculates and displays the sum of positive even numbers and negative odd numbers. It terminates when the user enters 0.
3) A program that removes all zeros from a user-input number and displays the resulting number. It reverses the number, removes zeros, and then reverses it back to get the final number.
The document contains 3 Java programs:
1) A program to display the first ten terms of the series 1, 12, 123, 1234 etc. by using nested for loops.
2) A program that takes numbers from user input, calculates and displays the sum of positive even numbers and negative odd numbers. It terminates when the user enters 0.
3) A program that removes all zeros from a user-input number and displays the resulting number. It reverses the number, removes zeros, and then reverses it back to get the final number.
The document contains 3 Java programs:
1) A program to display the first ten terms of the series 1, 12, 123, 1234 etc. by using nested for loops.
2) A program that takes numbers from user input, calculates and displays the sum of positive even numbers and negative odd numbers. It terminates when the user enters 0.
3) A program that removes all zeros from a user-input number and displays the resulting number. It reverses the number, removes zeros, and then reverses it back to get the final number.
Write a program to display the first ten terms of the series:
1, 12, 123, 1234,…………………………………..
class Q1e { public static void main(String s[]) { int i,j; for(i=1;i<=10;i++) { for(j=1;j<=i;j++) System.out.print(j); System.out.print(“,”); } } }
@@@@@@@@@@@@@@@@@@@@@@@@@@
Q6: WRITE A PROGRAM TO DISPLAY THE SUM OF POSITIVE
EVEN NUMBERS AND NEGATIVE ODD NUMBERS FROM A LIST OF NUMBERS ENTERED BY THE USER .THE LIST TERMINATES WHEN THE USER ENTERS ZERO AND DISPLAYS THE RESULT Public class Q6 { public static void main(String s[]) { Scanner in = new Scanner(System.in); int n=1,s1=0,s2=0; while(n!=0) { System.out.println(“ENTER ZERO TO END”); n=in.nextInt(); If(n==0) break; else { If(n>0 && n%2 == 0) S1=s1+n; If(n<0 && n%2 != 0) S2=s2+n; } } System.out.println(“The sum of possitive even numbers “,+s1); System.out.println(“The sum of negative odd numbers “,+s2); } @@@@@@@@@@@@@@@@@@@@@@@@@@@ JAVA program to accept a number and displaying new number after removing zeros in it (input:10205 output: 125) import java.util.Scanner;
public class removing_zero
{ public static void main(String args[]) { int num,rev_num=0,r,n,new_num=0; Scanner in = new Scanner(System.in); System.out.println("\n Plz enter a number"); n=in.nextInt(); num=n; while(n>0) { r=n%10; if(r!=0) { rev_num = rev_num*10+r; } n=n/10; } System.out.println("\n the reverseof the number after removing zeros "+rev_num); while(rev_num >0) { r=rev_num%10; new_num = new_num*10+r; rev_num=rev_num/10; } System.out.println("\n the new number number after removing zeros "+new_num); }}